小编fan*_*0me的帖子

连接套接字上的read()函数可以返回零字节吗?

我知道read()是一个阻塞调用,除非我使套接字无阻塞.所以我希望read()调用请求4K数据应该返回一个正值(没有读取的字节数)或错误的-1(客户端可能的连接重置等).我的问题是:read()可以在任何场合返回'0'吗?

我这样处理read():

   if ((readval = read(acceptfd, buf, sizeof(buf) - 1)) < 0)
    {

    }
    else
    {
       buf[readval] = 0;
       //Do some thing with data  
    }
Run Code Online (Sandbox Code Playgroud)

如果read()返回零,这段代码就会爆炸,我知道如何修复它.但是read()有可能返回零吗?

sockets linux network-programming tcp runtime-error

28
推荐指数
1
解决办法
4万
查看次数

TCP客户端 - 服务器"错误地址"错误(在C中)

虽然它似乎正确实现,但是当我使用环回地址(127.0.0.1)建立连接时,它会继续返回ERROR.

除了简单的TCP客户端/服务器连接外,我还添加了一个案例:

如果客户端尝试发送数据但发现连接已关闭,则它也会关闭.我通过检查接收的数据是否等于0(recv)来执行它.

给定错误:

CLIENT:
Welcome to the Client mode
Please, enter the Server's IP Address and Port (eg. 192.128.192.0 1320) 
127.0.0.1 2700
Connected to the server. Now you can send messages
Please, enter a message. Enter "FINISH" if you want to finish the connection
ECHO 
client: connection closed ->: Success
 (1 bytes)Closing the connection 

SERVER:
Hello and welcome to the Server mode
Please, enter the Server's Port …
Run Code Online (Sandbox Code Playgroud)

c sockets network-programming tcp

0
推荐指数
1
解决办法
6998
查看次数

"[(),()]"Haskell中的数组

最近,我一直在使用Haskell和QuickCheck进行自动测试.有些时候我有一些失败,但程序检索[(),()]为检查参数.

什么"[(),()]"意思?

automated-tests haskell quickcheck

0
推荐指数
1
解决办法
124
查看次数

杰基尔:'关于'永久链接不能正常工作

我正在使用Lanyon主题配置一个Jekyll网站,但网站url,baseurl和permalinks上的配置对我来说是如此不清楚.

因此我的_config.yml用途:

url: "https://edgeoftech.github.io/"
baseurl: /blog
permalink: pretty
Run Code Online (Sandbox Code Playgroud)

我的about.md页面使用:

permalink: /about
Run Code Online (Sandbox Code Playgroud)

提供网站时,主页面在页面上http://127.0.0.1:4000/blog/和页面附近提供http://127.0.0.1:4000/blog/about,但网站上的ABOUT链接将我带到http://127.0.0.1:4000/about.

如何配置链接和"关于"页面链接到同一个网址?

configuration permalinks jekyll github-pages

0
推荐指数
1
解决办法
906
查看次数