<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><br></div> <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"> <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1"> <b><span style="font-weight: bold;">From:</span></b> Stanciu Alexandru <the_marian_2006@yahoo.com><br> <b><span style="font-weight: bold;">To:</span></b> "so@cursuri.cs.pub.ro" <so@cursuri.cs.pub.ro> <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, April 3, 2012 7:23 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [so] Coada non-blocanta<br> </font> </div> <br>
<div id="yiv1124926619"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: times new roman,new york,times,serif; font-size: 12pt;"><div><span></span></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"> <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1"> <b><span style="font-weight: bold;">From:</span></b> Daniel Baluta <daniel.baluta@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Stanciu Alexandru <the_marian_2006@yahoo.com>; Sisteme de Operare <so@cursuri.cs.pub.ro> <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, April 3, 2012 6:27 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [so] Coada non-blocanta<br> </font> </div> <br>
2012/4/3 Stanciu Alexandru <<a rel="nofollow" ymailto="mailto:the_marian_2006@yahoo.com" target="_blank" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>:<br>><br>><br>> ________________________________<br>> From: Daniel Baluta <<a rel="nofollow" ymailto="mailto:daniel.baluta@gmail.com" target="_blank" href="mailto:daniel.baluta@gmail.com">daniel.baluta@gmail.com</a>><br>> To: Stanciu Alexandru <<a rel="nofollow" ymailto="mailto:the_marian_2006@yahoo.com" target="_blank" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>; Sisteme de Operare<br>> <<a rel="nofollow" ymailto="mailto:so@cursuri.cs.pub.ro" target="_blank" href="mailto:so@cursuri.cs.pub.ro">so@cursuri.cs.pub.ro</a>><br>> Sent: Tuesday, April 3, 2012 6:18 AM<br>><br>> Subject: Re: [so] Coada non-blocanta<br>><br>> 2012/4/3 Stanciu Alexandru <<a rel="nofollow"
ymailto="mailto:the_marian_2006@yahoo.com" target="_blank" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>:<br>>> ________________________________<br>>>
From: Daniel Baluta <<a rel="nofollow" ymailto="mailto:daniel.baluta@gmail.com" target="_blank" href="mailto:daniel.baluta@gmail.com">daniel.baluta@gmail.com</a>><br>>> To: Stanciu Alexandru <<a rel="nofollow" ymailto="mailto:the_marian_2006@yahoo.com" target="_blank" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>; Sisteme de Operare<br>>> <<a rel="nofollow" ymailto="mailto:so@cursuri.cs.pub.ro" target="_blank" href="mailto:so@cursuri.cs.pub.ro">so@cursuri.cs.pub.ro</a>><br>>> Sent: Tuesday, April 3, 2012 6:07 AM<br>>> Subject: Re: [so] Coada non-blocanta<br>>><br>>> 2012/4/3 Stanciu Alexandru <<a rel="nofollow" ymailto="mailto:the_marian_2006@yahoo.com" target="_blank" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>:<br>>>> Vreau sa fac si eu o coada non-blocanta, astfel incat, cand fac un<br>>>> receive<br>>>> sa nu se
blocheze executia ci sa sara mai departe pana cand primeste<br>>>> ceva.<br>>>> Am facut
asa:<br>>>><br>>>> message_t *buf = (message_t*) calloc (1, sizeof(message_t));<br>>>><br>>>> mqd_t q;<br>>>><br>>>> struct mq_attr attr;<br>>>> attr.mq_flags = O_NONBLOCK;<br>>>> attr.mq_maxmsg = 10;<br>>>> attr.mq_msgsize = sizeof(message_t);<br>>>> attr.mq_curmsgs = 0;<br>>>><br>>>> q = mq_open("/gateway", O_CREAT | O_RDWR, 0644, &attr);<br>>>><br>>>> while(1)<br>>>> {<br>>>> rc = mq_receive(q, (char *)buf, sizeof(message_t), NULL);<br>>><br>>> Ce se întâmplă dacă al treilea argument este sizeof(message_t) + 1?<br>>><br>>>><br>>>> In while, daca rc != -1 afisez datele din mesaj
altfel un mesaj oarecare.<br>>>> Problema este ca coada se blocheaza. Poate sa-mi zici si mie cineva de ce<br>>>> coada mea este blocanta totusi? Afisam mesaj imediat dupa receive si nu<br>>>> ajungea acolo.<br>>><br>>> Poți folosi strace să vezi apelurile de sistem făcute.<br>>><br>>> strace ./program<br>>><br>>> thanks,<br>>> Daniel<br>>><br>>><br>>> In apelul mq_open am pus attr si NU &attr si a mers.<br>><br>> Imposibil! :)<br>><br>> Am pus -1 la receive:). Daca pun la attr merge. Multumesc! Dar de ce a<br>> trebuit sa pun +1?<br><br>man mq_receive:<br><br>The msg_len argument specifies the size of the buffer pointed to by msg_ptr;<br>this must be greater than the mq_msgsize attribute of the queue.<br><br>thanks,<br>Daniel.<br><br>Tot nu este bine:(. Daca dau la attr sizeof(message_t) + 1 intradevar nu mai este blocanta, dar cand fac receive,
cu buffer size egal cu sizeof(message_t) nu preia mesajul si se blocheaza; daca dau buffer size in receive egal cu sizeof(message_t) + 1 imi preia mesajul, dar coada este iar blocanta, adica daca nu trimit ceva nu mai trece de receive. Care ar mai fi problema acum?<br><br><br>Deci daca fac combinatiile:<br>1. attr.mq_msgsize = sizeof(message_t) + 1 cu rc = mq_receive(q, (char *)buf, sizeof(message_t), NULL); imi executa tot ce se afla sub receive(coada este neblocanta) dar cand trimit ceva pe coada de la client nu receptioneaza(se blocheaza)<br>2. attr.mq_msgsize = sizeof(message_t) cu rc = mq_receive(q, (char
*)buf, sizeof(message_t) + 1, NULL); coada este blocanta; pana cand nu trimit ceva pe coada, nu se executa nimic dupa receive<br>3. attr.mq_msgsize = sizeof(message_t) cu rc = mq_receive(q, (char
*)buf, sizeof(message_t), NULL); ca la 2<br><br>Declar coada ca fiind neblocanta; poate sa-mi zica si mie cineva unde gresesc?(sterg toate cozile create)<br><br><br> </div> </div> </div></div></div><br><br> </div> </div> </div></body></html>