Linux Newbie help
 help / color / mirror / Atom feed
From: "Lee Chin" <leechin@mail.com>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: Mark Hahn <hahn@physics.mcmaster.ca>,
	linux-net@vger.kernel.org, linux-newbie@vger.kernel.org
Subject: Re: is sendto and recvfrom thread safe?
Date: Thu, 21 Aug 2003 15:02:26 -0500	[thread overview]
Message-ID: <20030821200226.59291.qmail@mail.com> (raw)

This sort  of helps... my question is with respect to UDP sockets, for sendto and recvfrom, can I concurrently have two threads at the same time write (sendto) on a same file descriptor?  How about readfrom and sendt on the same file descriptor at the same time?

Thanks
Lee
----- Original Message -----
From: Stephen Hemminger <shemminger@osdl.org>
Date: Thu, 21 Aug 2003 09:16:49 -0700
To: "Lee Chin" <leechin@mail.com>
Subject: Re: is sendto and recvfrom thread safe?

> On Thu, 21 Aug 2003 01:06:45 -0500
> "Lee Chin" <leechin@mail.com> wrote:
> 
> > Hi,
> > If I have a global socket file descriptor, can I call sendto and recvfrom on that file descriptor concurrently with out using semaphores around the call to sendto and recvfrom?
> > 
> > What about for TCP sockets?
> > 
> > Thanks
> > Lee
> 
> It depends on your definition of thread safe.
> Sendto and recvfrom are for UDP which is a datagram protocol; therefore
> each call sends and receives a separate data unit.  The application protocol
> has to be atomic to work with UDP anyway. Your application has to deal
> with out of order, and dropped packets.
> 
> If you use TCP sockets with threaded applications you better do application
> level locking per socket and have enough information in your protocol to describe
> the length of each operation.  TCP is a byte stream, and with multiple threads sending
> it is possible to "mix the streams".  Multiple threads reading will get out of
> order data.
> 
> This is true of all OS's that I know about that support threads 
> (Windows, Solaris, Linux, ...).

-- 
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers


             reply	other threads:[~2003-08-21 20:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-21 20:02 Lee Chin [this message]
2003-08-21 21:33 ` is sendto and recvfrom thread safe? Stephen Hemminger
  -- strict thread matches above, loose matches on Subject: below --
2003-08-21  6:06 Lee Chin
2003-08-21 16:16 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030821200226.59291.qmail@mail.com \
    --to=leechin@mail.com \
    --cc=hahn@physics.mcmaster.ca \
    --cc=linux-net@vger.kernel.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=shemminger@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox