Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [TcpSocket] Receive does not block  (Read 2008 times)

0 Members and 1 Guest are viewing this topic.

omicronns

  • Newbie
  • *
  • Posts: 1
    • View Profile
[TcpSocket] Receive does not block
« on: December 18, 2014, 01:58:37 am »
Here is a minimal example of my problem:

int main(int argc, char **argv) {
    sf::TcpListener lst;
    lst.listen(10000);
    sf::TcpSocket sck;
    lst.accept(sck);

    while(true) {
        char data[10];
        unsigned long len;
        sck.receive(data, 10UL, len);
        sck.send(data, len);
    }
}
 

Following program after receiving a packet starts to put following message to stdout: "Cannot send data over the network (no data to send)", however i can receive first echo reply as a source of this packet. As I found, it is a message prompted by send function when called with len=0. But shouldn't receive method wait until it receives some portion of data in default blocking mode?

If i do something like that it's working as desired:

int main(int argc, char **argv) {
    sf::TcpListener lst;
    lst.listen(10000);
    sf::TcpSocket sck;
    lst.accept(sck);

    while(true) {
        char data[10];
        unsigned long len;
        do {
            sck.receive(data, 10UL, len);
        } while(len == 0);
        sck.send(data, len);
    }
}
 

Am I misunderstanding something?

I'm running on Ubuntu 14.10 using [libsfml-network2 2.1+dfsg2-1] library, code compiled with [g++ 4:4.9.1-4ubuntu2]

Thanks for your help in advance
« Last Edit: December 18, 2014, 02:02:46 am by omicronns »