Question

When you run this code, the response does not come. Soket is a state of being connected. So forever is in the standby state return value without not. please help me.

...
sock = socket(PF_INET, protocol, 0);
...
char recv_data[102400] = {0,};

while ((size=recv(sock,recv_data,102400-1, 0)) > 0){
    // some code
}
...

OS : SunOS xname 5.10 Generic_147440-12 sun4u sparc SUNW,Sun-Fire-15000

Was it helpful?

Solution

I am guessing the socket is blocking.

int noblock(int fd)
{
      int flags = fcntl(fd, F_GETFL, 0);
      if (flags < 0) return 0;
      flags = (blocking) ? (flags&~O_NONBLOCK) : (flags|O_NONBLOCK);
      return (fcntl(fd, F_SETFL, flags) == 0) ? 1 : 0;
}

Use this to set the socket to non-blocking. When there is no data to read, recv() will return a -1 and set errno to EWOULDBLOCK

See if those changes get you past your current problem.

You really should be checking the return codes of all you calls

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top