Hi, When doing simple socket reads should I use read() or actually
use recv() (with the flags value set to zero). I believe they'll do
exactly the same thing? Which one is the preferred style? Is there
any consideration that I'm missing?
Thanks,
MC
|
|
0
|
|
|
|
Reply
|
spamspamspam3 (19)
|
7/21/2011 9:15:20 PM |
|
In <4e2896ed$0$35553$c3e8da3$4db35a27@news.astraweb.com> Martin Crouch <spamspamspam@spaml.com> writes:
> Hi, When doing simple socket reads should I use read() or actually
> use recv() (with the flags value set to zero). I believe they'll do
> exactly the same thing? Which one is the preferred style? Is there
> any consideration that I'm missing?
If you need the extra control that the "flags" argument provides, then
you must (obviously) use recv().
If you don't, and would therefore set "flags" to zero, then the two methods
are identical. In that case I would assume the preferred style is to use
read(), which more clearly broadcasts your intentions to whomever is
reading the code.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
|
|
0
|
|
|
|
Reply
|
gordon16 (617)
|
7/21/2011 9:54:33 PM
|
|
Martin Crouch <spamspamspam@spaml.com> writes:
> Hi, When doing simple socket reads should I use read() or actually
> use recv() (with the flags value set to zero). I believe they'll do
> exactly the same thing? Which one is the preferred style?
There is presumably no such thing as 'a preferred style'. My opinion
on that would be that recv is less universal (only for sockets) and
more complicated (because of the flags argument) than read and because
of this, I think using read where it is sufficient should be preferred
over using recv where it isn't needed.
|
|
0
|
|
|
|
Reply
|
rweikusat (2678)
|
7/21/2011 10:03:03 PM
|
|
On Thu, 21 Jul 2011 22:15:20 +0100, Martin Crouch wrote:
> Hi, When doing simple socket reads should I use read() or actually use
> recv() (with the flags value set to zero). I believe they'll do exactly
> the same thing? Which one is the preferred style? Is there any
> consideration that I'm missing?
There's no reason to use recv() without flags. You may as well just use
read(). Or use fdopen() and stdio.
Not using recv() has the advantage that portions of the code may work on
something other than a socket.
|
|
0
|
|
|
|
Reply
|
nobody (4804)
|
7/22/2011 3:35:26 PM
|
|
Nobody <nobody@nowhere.com> wrote:
> On Thu, 21 Jul 2011 22:15:20 +0100, Martin Crouch wrote:
>
>> Hi, When doing simple socket reads should I use read() or actually use
>> recv() (with the flags value set to zero). I believe they'll do exactly
>> the same thing? Which one is the preferred style? Is there any
>> consideration that I'm missing?
>
> There's no reason to use recv() without flags. You may as well just use
> read(). Or use fdopen() and stdio.
>
> Not using recv() has the advantage that portions of the code may work on
> something other than a socket.
>
Using recv() and send() makes it easier to port the code to winsock (at
least this used to be the case, things may have changed).
--
Huibert
"Okay... really not something I needed to see." --Raven
|
|
0
|
|
|
|
Reply
|
huibert.bol (74)
|
7/22/2011 5:20:30 PM
|
|
Huibert Bol <huibert.bol@quicknet.nl> writes:
> Nobody <nobody@nowhere.com> wrote:
>> On Thu, 21 Jul 2011 22:15:20 +0100, Martin Crouch wrote:
>>
>>> Hi, When doing simple socket reads should I use read() or actually use
>>> recv() (with the flags value set to zero). I believe they'll do exactly
>>> the same thing? Which one is the preferred style? Is there any
>>> consideration that I'm missing?
>>
>> There's no reason to use recv() without flags. You may as well just use
>> read(). Or use fdopen() and stdio.
>>
>> Not using recv() has the advantage that portions of the code may work on
>> something other than a socket.
>>
>
> Using recv() and send() makes it easier to port the code to winsock (at
> least this used to be the case, things may have changed).
Holy contagious contortion ...
|
|
0
|
|
|
|
Reply
|
rweikusat (2678)
|
7/22/2011 6:49:08 PM
|
|
Huibert Bol <huibert.bol@quicknet.nl> wrote:
> Nobody <nobody@nowhere.com> wrote:
> > On Thu, 21 Jul 2011 22:15:20 +0100, Martin Crouch wrote:
> >
> >> Hi, When doing simple socket reads should I use read() or actually use
> >> recv() (with the flags value set to zero). I believe they'll do exactly
> >> the same thing? Which one is the preferred style? Is there any
> >> consideration that I'm missing?
> >
> > There's no reason to use recv() without flags. You may as well just use
> > read(). Or use fdopen() and stdio.
> >
> > Not using recv() has the advantage that portions of the code may work on
> > something other than a socket.
> >
> Using recv() and send() makes it easier to port the code to winsock (at
> least this used to be the case, things may have changed).
That's what I thought. But now my socket code uses #if _WIN32 because being
able to use pipes made writing regression tests much easier. I could, for
example, compile an asynchronous network protocol library into a shell
utility and feed it pathological cases from a script. No need to bother with
bootstrapping a sockets environment; even socketpair() would be infinitely
more bothersome.
|
|
0
|
|
|
|
Reply
|
William
|
7/22/2011 9:40:12 PM
|
|
On Jul 22, 8:35=A0am, Nobody <nob...@nowhere.com> wrote:
> Not using recv() has the advantage that portions of the code may work on
> something other than a socket.
Of course, if your code can't work on anything but sockets for some
other reason, using 'recv()' clearly broadcasts this.
DS
|
|
0
|
|
|
|
Reply
|
David
|
7/22/2011 10:14:48 PM
|
|
Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> Huibert Bol <huibert.bol@quicknet.nl> writes:
> > Using recv() and send() makes it easier to port the code to
> > winsock (at least this used to be the case, things may have
> > changed).
> Holy contagious contortion ...
http://www.netperf.org/ ... although I'm not sure if the WIN32 stuff
actually still compiles presently.
rick jones
entertains the notion of a "native API" version for netperf WIN32...
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
|
|
0
|
|
|
|
Reply
|
rick.jones2 (1061)
|
7/22/2011 10:21:43 PM
|
|
David Schwartz <davids@webmaster.com> writes:
> On Jul 22, 8:35�am, Nobody <nob...@nowhere.com> wrote:
>> something other than a socket.
>
> Of course, if your code can't work on anything but sockets for some
> other reason, using 'recv()' clearly broadcasts this.
But except if the flags argument to recv is actually used, the part of
the code which deals with receiving the data _can_ work on all kinds
of file descriptors.
|
|
0
|
|
|
|
Reply
|
rweikusat (2678)
|
7/22/2011 10:35:44 PM
|
|
Martin Crouch wrote:
> Hi, When doing simple socket reads should I use read() or actually
> use recv() (with the flags value set to zero). I believe they'll do
> exactly the same thing? Which one is the preferred style? Is there
> any consideration that I'm missing?
>
> Thanks,
>
> MC
Here's a nice tutorial.
http://beej.us/guide/bgnet/output/html/multipage/index.html
Unix socket programming is a good book too. Great book! rec() depends
somewhat on the type of sockets your using. TCP or UDP.
Bill
|
|
0
|
|
|
|
Reply
|
nospam116 (1187)
|
7/28/2011 5:27:01 PM
|
|
|
10 Replies
69 Views
(page loaded in 0.221 seconds)
Similiar Articles: Can 'recv' return EPIPE? - comp.unix.programmerInterrupted system calls (socket read) , EINTR and SIGTERM - comp ... > If I receive the signal when middle of the read doing ... But I don't know if you are aware that ... How full is a UDP socket buffer - comp.unix.programmerHi, Here is the reason why I need to know how full a UDP socket's receive buffer. ... Oh, and before you say set and read socket buffer sizes are the same, try this ... Understanding Send-Q and Recv-Q by netstat - comp.os.linux ...Oh, and before you say set and read socket buffer sizes are the same, try this ... Christophe Lohr a crit : > ... sorry, I don't understand what are socket receive ... Problem sending binary file via socket. - comp.unix.programmer ...... to send? > > > } > > fclose(fp); > > > my server code: > > > if (bytes_read = recv ... Problem sending binary file via socket. - comp.unix.programmer ... File Transfer ... "Interrupted system call", read and socket - comp.unix.programmer ...Typically, you will receive this error when the syscall blocks and a signal is ... "Interrupted system call", read and socket - comp.unix.programmer ... "Interrupted system ... timeout on tcp/ip read? - comp.unix.programmerHow do I configure a socket such that if I call read and no data is available after 60 seconds ... don't think there's a portable way to do this just with read() or recv(). Using a MPI_RECV and MPI_REDUCE - comp.parallel.mpiMy output file reads: p1_10028: p4_error: net_recv read: probable EOF on socket: 1 p2_9496: p4_error: net_recv read: probable EOF on socket: 1 p3_14385: p4_error: net ... Interrupted system calls (socket read) , EINTR and SIGTERM - comp ...If I receive the signal when middle of the read doing some thing, after signal handler return. The read function trying to read some thing on the socket and got hung ... Sending an array of astruct over a TCP socket (Using C). - comp ...You should use send(2) with MSG_DONTWAIT and recv(2) instead of write(2) and read(2)! Or set socket options: SO_RCVLOWAT and SO_SNDLOWAT Specify ... Nonblocking socket read gets lots of EAGAIN - comp.unix.programmer ...I am writing a web server load test tool, like JMeter, but in UNIX/C, using non-blocking socket (fcntl O_NONBLOCK). My read() gets lots of -1 retur... recv function - Microsoft Corporation: Software, Smartphones ...The recv function is used to read incoming data on connection-oriented sockets, or connectionless sockets. When using a connection-oriented protocol, the ... recv - Microsoft Corporation: Software, Smartphones, Online, Games ...int recv( SOCKET s, char FAR* buf ... until it is successfully read by calling recv with a large enough buffer. If no incoming data is available at the socket, the ... 7/29/2012 11:13:28 AM
|