Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

socket read buffer full

by targetsmart (Curate)
on Jan 06, 2009 at 10:34 UTC ( [id://734398]=perlquestion: print w/replies, xml ) Need Help??

targetsmart has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,
I faced one problem with sockets and found a solution I just wanted to know I am correct.
I had two socket programs, A and B, A will be receiving data from B, A's socket only reads and B's socket only writes.
Now when the A's socket apart from reading also tends to write some data into the B's socket, but B is not reading, this makes both the program A and B to hang after some time.
I predicted that the read side of the socket is full in B side, so I started to read the data from B's side also apart from writing, the problem got solved.
Now my question is, can we set up a socket(TCP/IP) in such a way that it only writes or reads.(because B is only a simulation program). or just ignore read side at the socket level.

Replies are listed 'Best First'.
Re: socket read buffer full
by sathiya.sw (Monk) on Jan 06, 2009 at 15:24 UTC
                 Now my question is, can we set up a socket(TCP/IP) in such a way that it only writes or reads. 
    When you do shutdown of an end, you can do only the other operation. Hope this helped.

    As per your explanation, if B is not intended for reading, then do the shutdown of read end at B, and write end of A..

    Sathiyamoorthy
Re: socket read buffer full
by Dhanasekar (Acolyte) on Jan 06, 2009 at 12:24 UTC
    One of the wisdom I got from your post is that one can read and write between the process with a single TCP connection. Also I cross verified from the below link
    Note: Actual point discussed over the link specified is not related to this !! But it has underlying concepts related to the TCP !!
    So there is nothing wrong in performing both read and write in a single socket. Define in your coding as per your requirement/need in both end of the connection ( i.e in two related process ) !!
Re: socket read buffer full
by spmlingam (Scribe) on Jan 07, 2009 at 07:29 UTC
    You can use the select on socket handler, which will let you know whether the socket is ready for read or write. Based on the select output you can perform read or write operation.
      This question is ignoring reads, to avoid blocking.

        spmlingam's answer does address your problem. When B is about to write, use select to check if there's anything to read. If there's is, read until there isn't. Then proceed to write.

        sathiya.sw's shutdown solution sounds more promising, though.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://734398]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-24 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found