Networking Forums

Networking Forums > Computer Networking > Linux Networking > SO_SNDLOWAT not avalaible; how can i avoid non-blocking sockets

Reply
Thread Tools Display Modes

SO_SNDLOWAT not avalaible; how can i avoid non-blocking sockets

 
 
przemas_r@o2.pl
Guest
Posts: n/a

 
      11-24-2004, 04:02 PM
Hi all!

I'm writing socket app, which will transmit data in fixed size packets.
I'd like to be able to pass N bytes to send (or write) function and
ensure that it won't block.

I was willing to set SO_SNDLOWAT option properly and use select to avoid
blocking send. On linux it's impossible, because SO_SNDLOWAT option is
unavailable. After one hour fruitless googling and newsgroup browsing I
had to give up.

I know I can achieve desirable effect by using non-blocking sockets. But
due to its CPU-consuming nature I treat it as last resort.

--
Przemysław Różycki
 
Reply With Quote
 
 
 
 
Rick Jones
Guest
Posts: n/a

 
      11-24-2004, 05:35 PM
(E-Mail Removed) wrote:
> I'm writing socket app, which will transmit data in fixed size
> packets. I'd like to be able to pass N bytes to send (or write)
> function and ensure that it won't block.


Does your application have any data arriving from the other end -
perhaps replies to messages you previously sent?

> I was willing to set SO_SNDLOWAT option properly and use select to
> avoid blocking send. On linux it's impossible, because SO_SNDLOWAT
> option is unavailable. After one hour fruitless googling and
> newsgroup browsing I had to give up.


> I know I can achieve desirable effect by using non-blocking
> sockets. But due to its CPU-consuming nature I treat it as last
> resort.


If you go into a select or poll call it shouldn't be all that bad.
Typically, TCP will window update for non-trivial quantities of data -
O(2MSS) so it won't be as if you would be writing a single byte into
the socket all the time. Of course, it won't be a whopping 8KB or
what have you.

If you have messages coming back, you can use them to determine when,
beyond a shadow of a doubt some quantity of data has left your
SO_SNDBUF. If you receve some application-level ack of message N, you
know that means that the remote has received that message, which means
that TCP has received that message, and likely as not has piggy-backed
an ACK and TCP window update to the reply message (if not sooner).
That means you know that there are at least sizeof(messageN) bytes
available in your SO_SNDBUF.

Similarly, if you know you never have more than M of these messages
outstanding at any one time, if you make your SO_SNDBUF
M*sizeof(message) bytes in size, you will "know" that you can write an
entire message into the socket in one call.

rick jones
--
portable adj, code that compiles under more than one compiler
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to raj in cup.hp.com but NOT BOTH...
 
Reply With Quote
 
=?ISO-8859-2?Q?Przemys=B3aw_R=F3=BFycki?=
Guest
Posts: n/a

 
      11-26-2004, 09:10 PM
Thanks a lot for your answer. You presented handful useful solutions.
I have chosen even the other one. Now all connections are in blocking
mode, but each of connections has a thread dedicated to it. I hope this
will work as expected.

Cheers!
 
Reply With Quote
 
Rick Jones
Guest
Posts: n/a

 
      11-29-2004, 05:47 PM
Przemys?aw R??ycki <(E-Mail Removed)> wrote:
> Thanks a lot for your answer. You presented handful useful
> solutions. I have chosen even the other one. Now all connections
> are in blocking mode, but each of connections has a thread dedicated
> to it. I hope this will work as expected.


There was a reason I didn't mention threads Threads can be quite
convenient, heck, sometimes even useful However, "connection per
thread" isn't exactly the most "scalable" of solutions out there. I
personally do not see it as being all that much better than
"connection per process." Just keep that in mind if you decide to
scale your application out to more than a "few" (for some, rather
fluid definition of "few" ) connections.

rick jones
--
Process shall set you free from the need for rational thought.
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to raj in cup.hp.com but NOT BOTH...
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Broadband - what to go for & what to avoid Petert Broadband 16 08-28-2008 10:10 AM
What is difference of SYNC, ASYNC, BLOCKING, NON-BLOCKING sockets? kevin Linux Networking 0 11-21-2005 09:56 AM
SO_SNDLOWAT Redux bobrudinski Linux Networking 0 09-14-2004 12:15 AM
Real-Time UDP non-blocking sockets in Linux Michael Drew Linux Networking 14 02-18-2004 11:56 PM
Avoid myinternetpass.com anon Broadband 2 10-28-2003 06:52 PM



1 2 3 4 5 6 7 8 9 10 11