Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Question about socketpair: (3 Items)
   
Question about socketpair  
Does anyone know of any way to write to a socket and block until the data has been read at the other end?

Apparently, the socket has some sort of receiving/sending buffer (SO_RCVBUF/SO_SNDBUF options), I was thinking maybe we 
can change the value to block write(). So I tried setting the buffer size to 1 byte, and for some reason it didn't work:
 setsockopt() returned correctly, but write() function was not blocked anyway. I also tried buffer size 16 and 64 byte, 
they didn't work either.

Any idea?

Thanks.

//*************** Code ***************************
    int size = 1;
    if (setsockopt(fda[0], SOL_SOCKET, SO_RCVBUF, &size, sizeof(int)) < 0){
        cout << "something is wrong" << endl;
    }
    
    if (setsockopt(fda[1], SOL_SOCKET, SO_SNDBUF, &size, sizeof(int)) < 0){
        cout << "something is wrong" << endl;
    }
RE: Question about socketpair  
No you can't, that's not how TCP/IP is designed.

-----Original Message-----
From: Zhenwang Yao [mailto:zhenwang.yao@gmail.com] 
Sent: Wednesday, April 16, 2008 5:45 PM
To: general-community
Subject: Question about socketpair


Does anyone know of any way to write to a socket and block until the data
has been read at the other end?

Apparently, the socket has some sort of receiving/sending buffer
(SO_RCVBUF/SO_SNDBUF options), I was thinking maybe we can change the value
to block write(). So I tried setting the buffer size to 1 byte, and for some
reason it didn't work: setsockopt() returned correctly, but write() function
was not blocked anyway. I also tried buffer size 16 and 64 byte, they didn't
work either.

Any idea?

Thanks.

//*************** Code ***************************
    int size = 1;
    if (setsockopt(fda[0], SOL_SOCKET, SO_RCVBUF, &size, sizeof(int)) < 0){
        cout << "something is wrong" << endl;
    }
    
    if (setsockopt(fda[1], SOL_SOCKET, SO_SNDBUF, &size, sizeof(int)) < 0){
        cout << "something is wrong" << endl;
    }


_______________________________________________
General
http://community.qnx.com/sf/go/post6938

Re: RE: Question about socketpair  
Thanks,

I was actually trying to use it as a local socket stream, as

socketpair(AF_LOCAL, SOCK_STREAM, 0, fda) ;


> No you can't, that's not how TCP/IP is designed.
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post6938
>