c - 读取函数没有返回任何值

标签 c sockets

n 的值即将为 9,sockfd = 3 并且当它调用读取函数时,它不是从读取函数中出来的。打印读取起始行后,它仅停在那里:

while(1)
{
        if (n < 0)  
            {
                printf("ERROR writing to socket");              
            }   
        else if(n == 0)
            {
                printf("Nothing");

            }
            printf(" read start n=%d\n ,sockfd = %d\n",n,sockfd);
            n = read(sockfd,buffer,1024);

        if (n < 0)
            {   error("ERROR reading from socket");
            }
            printf("Reply= %s",buffer);
            write_buf_to_file("/root/abc_regr/receive.txt",buffer);  
}
return;

最佳答案

read() 默认情况下是阻塞调用,因此它将等待直到获取数据。如果您想要非阻塞功能,请阅读 this 的答案问题。

关于c - 读取函数没有返回任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27916499/

相关文章:

c - location pragmas需要什么

java - 通过ByteBuffer传输字符串

java - 使用流关闭套接字

使用字符串调用 free() 会出现 *** glibc detected *** 错误

c - ARM恩智浦LPC2378 : Is is safe to modify GPIO pin output state via register access?

C程序argv不包含双引号

c - 以 float 和 int 表示形式计算 c 中表达式的不同值?

c - 获取对端IP地址和端口

c++ - 从服务器c++向客户端发送命令

java - udp打洞端口错误?