* write() udp socket
@ 2011-07-23 9:29 ZHOU Xiaobo
2011-07-24 8:33 ` Huajun Li
0 siblings, 1 reply; 5+ messages in thread
From: ZHOU Xiaobo @ 2011-07-23 9:29 UTC (permalink / raw)
To: netdev
question No1:
When I call
ssize_t write(int fd, const void *buf, size_t count);
on a nonblocking UDP socket, is the return value always equal to 'count'?
question No2:
Can I write() a UDP socket in multiple threads without locking?
thanks
------------------
Sincerely yours
ZHOU Xiaobo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: write() udp socket
2011-07-23 9:29 write() udp socket ZHOU Xiaobo
@ 2011-07-24 8:33 ` Huajun Li
2011-07-25 17:38 ` Rick Jones
0 siblings, 1 reply; 5+ messages in thread
From: Huajun Li @ 2011-07-24 8:33 UTC (permalink / raw)
To: ZHOU Xiaobo; +Cc: netdev
2011/7/23 ZHOU Xiaobo <xb.zhou@qq.com>:
> question No1:
> When I call
> ssize_t write(int fd, const void *buf, size_t count);
>
>
> on a nonblocking UDP socket, is the return value always equal to 'count'?
>
>
I don't think so. The function may be interrupt by signal or return
due to other reason, so the return value only represents the size it
writes successfully to the fd.
> question No2:
> Can I write() a UDP socket in multiple threads without locking?
>
In my opinion, you could. However, the receiver may not get what you expected.
>
> thanks
>
>
> ------------------
> Sincerely yours
> ZHOU Xiaobo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: write() udp socket
2011-07-24 8:33 ` Huajun Li
@ 2011-07-25 17:38 ` Rick Jones
0 siblings, 0 replies; 5+ messages in thread
From: Rick Jones @ 2011-07-25 17:38 UTC (permalink / raw)
To: Huajun Li; +Cc: ZHOU Xiaobo, netdev
On 07/24/2011 01:33 AM, Huajun Li wrote:
> 2011/7/23 ZHOU Xiaobo<xb.zhou@qq.com>:
>> question No1:
>> When I call
>> ssize_t write(int fd, const void *buf, size_t count);
>>
>>
>> on a nonblocking UDP socket, is the return value always equal to 'count'?
>>
>>
>
> I don't think so. The function may be interrupt by signal or return
> due to other reason, so the return value only represents the size it
> writes successfully to the fd.
I believe it should either appaear to succeed or fail. write() best not
be sending partial UDP datagrams. That would be "bad."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: write() udp socket
@ 2011-07-26 5:32 ZHOU Xiaobo
0 siblings, 0 replies; 5+ messages in thread
From: ZHOU Xiaobo @ 2011-07-26 5:32 UTC (permalink / raw)
To: Rick Jones, Huajun Li; +Cc: netdev
------------------
Sincerely yours
ZHOU Xiaobo
------------------ Original ------------------
From: "Rick Jones"<rick.jones2@hp.com>;
Date: Tue, Jul 26, 2011 01:38 AM
To: "Huajun Li"<huajun.li.lee@gmail.com>;
Cc: "ZHOU Xiaobo"<xb.zhou@qq.com>; "netdev"<netdev@vger.kernel.org>;
Subject: Re: write() udp socket
On 07/24/2011 01:33 AM, Huajun Li wrote:
> 2011/7/23 ZHOU Xiaobo<xb.zhou@qq.com>:
>> question No1:
>> When I call
>> ssize_t write(int fd, const void *buf, size_t count);
>>
>>
>> on a nonblocking UDP socket, is the return value always equal to 'count'?
>>
>>
>
> I don't think so. The function may be interrupt by signal or return
> due to other reason, so the return value only represents the size it
> writes successfully to the fd.
I believe it should either appaear to succeed or fail. write() best not
be sending partial UDP datagrams. That would be "bad."
yeah, the same as I think. If so the answer of Question No.2 is 'yes' too?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: write() udp socket
@ 2011-07-26 5:39 ZHOU Xiaobo
0 siblings, 0 replies; 5+ messages in thread
From: ZHOU Xiaobo @ 2011-07-26 5:39 UTC (permalink / raw)
To: Huajun Li; +Cc: netdev
------------------
Sincerely yours
ZHOU Xiaobo
------------------ Original ------------------
From: "Huajun Li"<huajun.li.lee@gmail.com>;
Date: Sun, Jul 24, 2011 04:33 PM
To: "ZHOU Xiaobo"<xb.zhou@qq.com>;
Cc: "netdev"<netdev@vger.kernel.org>;
Subject: Re: write() udp socket
2011/7/23 ZHOU Xiaobo <xb.zhou@qq.com>:
> question No1:
> When I call
> ssize_t write(int fd, const void *buf, size_t count);
>
>
> on a nonblocking UDP socket, is the return value always equal to 'count'?
>
>
I don't think so. The function may be interrupt by signal or return
due to other reason, so the return value only represents the size it
writes successfully to the fd.
UDP is datagram, so I think it guarantees the 'buffer' in 'write()' is entirely sent
like an atomic operate.
> question No2:
> Can I write() a UDP socket in multiple threads without locking?
>
In my opinion, you could. However, the receiver may not get what you expected.
what will happen? I only concern whether the application 'buffer' is sent partially which
is unacceptable.
>
> thanks
>
>
> ------------------
> Sincerely yours
> ZHOU Xiaobo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-26 5:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-23 9:29 write() udp socket ZHOU Xiaobo
2011-07-24 8:33 ` Huajun Li
2011-07-25 17:38 ` Rick Jones
-- strict thread matches above, loose matches on Subject: below --
2011-07-26 5:32 ZHOU Xiaobo
2011-07-26 5:39 ZHOU Xiaobo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).