Message queue is not blocked in msgsnd


 
Thread Tools Search this Thread
Top Forums Programming Message queue is not blocked in msgsnd
# 1  
Old 09-22-2011
Network Message queue is not blocked in msgsnd

Hi, I am trying to send/receive data by message queue and expecting it to be blocked on send/read for other side (at least this is my understooding ) , I am connecting message between perl<->C , perl is working as expected , but in C msgsnd and msgrcv are not waiting (blocked) untill second side will read/write .
Here is a code I am using :

QueueId = msgget(QueueKey, 0777 | IPC_CREAT | IPC_EXCL );
if ((status=msgsnd(QueueId, &MsgBuf, s.length()+1, 0)) == -1) { /* +1 for '\0' */
fprintf(stderr,"Failing to send a message: \"%s\"...\n",s.c_str()),
msgctl(QueueId, IPC_RMID, NULL);
exit(-1);
};
msgrcv(QueueId, &MsgBuf, sizeof(MsgBuf.mtext), 0, 0);


Appreciate any help
# 2  
Old 09-22-2011
Check the return value of everything and whenever it's not what you expected, perror("something happened");. What's the value of QueueID?
# 3  
Old 09-22-2011
Quote:
Originally Posted by Corona688
Check the return value of everything and whenever it's not what you expected, perror("something happened");. What's the value of QueueID?
QueueID=1409024
The return statuses are : MSGSND:0 MSGRCV: 16
I am expecting this process stalled on msgsnd ... Correct ? But it doesn't ...
# 4  
Old 09-22-2011
Well, it's receiving a message. Check the contents, see what it received.
# 5  
Old 09-22-2011
Quote:
Originally Posted by Corona688
Well, it's receiving a message. Check the contents, see what it received.
Let me to describe a problem more precised :
I am expectin to open the message in other process in perl ,it should get a data from C->msgsnd and reply back to C-msgrcv.
I am expecting from C->msgsnd to be blocked untill perl will make msgrcv
and C->msgrcv to be blocked untill perl side will execute Perl->msgsnd .
However I don't run Perl at all and C->msgsnd should be stacked forever ...
However it execute msgsnd and msgread with previously send data without waiting ...
# 6  
Old 09-22-2011
Interesting, now I see why msgrcv can selectively ignore message types.

Have them send and receive different message types, blocking their own.

Code:
msg->mtype=1; // Send a type-1 message.
msgsnd(msqid, msg, msg_size, 0);
msgrcv(msqid, msg, msg_size, 1, MSG_EXCEPT); // Ignore type-1 messages

# 7  
Old 09-22-2011
Quote:
Originally Posted by Corona688
Interesting, now I see why msgrcv can selectively ignore message types.

Have them send and receive different message types, blocking their own.

Code:
msg->mtype=1; // Send a type-1 message.
msgsnd(msqid, msg, msg_size, 0);
msgrcv(msqid, msg, msg_size, 1, MSG_EXCEPT); // Ignore type-1 messages

Waw it is working , THANKS A LOT
(I spend half day on this stupid thing )Smilie
This User Gave Thanks to alexse For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Denyhosts displaying warning message for users blocked

Hi, I have a dilemma.I am running denyhosts on one of our servers and it monitors illegal ssh/ftp loggins. I am running vsftpd. My manager though has put an additional requirement on me. When someone is blocked my denyhosts he want an error message to be displayed: " YOUR ACCOUNT HAS BEEN... (0 Replies)
Discussion started by: mojoman
0 Replies

2. Ubuntu

Message Queue in Linux

Hello How can I see the created message queues in the system? (4 Replies)
Discussion started by: xyzt
4 Replies

3. Programming

UNIX Message Queue

Hello !!!!! I have a simple question but i can't find the answer anywhere hope to meet it here. Why it is a bad idea to pass pointers through message queues ? Most structs i see all of their char types are arrays... Is it becase having pointers means we could possibily send wrong bytes ? For... (2 Replies)
Discussion started by: qlyine
2 Replies

4. Programming

Message Queue Problem

Hi all, I need help about message queues, i have a server-client program that communicates each other via msg queue, firstly server opens its msg queue and waits for msg then client opens server msg queue and its own msg queue(for receiving msg from server,clients sends msg to server msg... (7 Replies)
Discussion started by: SaTYR
7 Replies

5. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

6. Programming

message queue

Hello, i need to write a message queue "chat server", that should work only localy. Can anyone please help me with some ideas and peshaps code. I'm studying the UNIX IPC mechanisms right now. So far, i understand how it works but i still cannot get an idea how to write a chat programm... ... (2 Replies)
Discussion started by: etenv
2 Replies

7. Programming

Message Queue with fork() help

hi all... ive been trying this program where i spawn 4 threads... and i am trying to use message queue to send msgs from 3 of the threads to the parent thread... but it doent seem to be working... ive almost pulled out my hair tryin to fix the prob :confused: another wierd thing... (1 Reply)
Discussion started by: strider
1 Replies

8. Programming

Message Queue Problem Again..

Is there any way one can delete , say , a particular message from a message queue on system V? (2 Replies)
Discussion started by: satansfury
2 Replies

9. Programming

a message queue question..

Hi there: Thanks first. When I use a message queue amony severl processes, will I have to synchronize the queue? I don't think I would have to because a message queue is implemented in a link listed. Correct me If I am wrong... (0 Replies)
Discussion started by: yanhu
0 Replies

10. UNIX for Advanced & Expert Users

Unix message Queue

Hi, I am working closly with unix message queues i have encountered the following - after creating the Q and start working with it (pushing & pulling) i receive the following stange parameters on the q's - STIME=no_entry Qnum=0 CBYTES=4140 when this happens, the Q is disabled (meaning i... (3 Replies)
Discussion started by: kel
3 Replies
Login or Register to Ask a Question