linux c socket read方法的疑问?

问下linux c socket read方法是不是遇到\r\n会自动返回?
还是需要程序主动分割,比如一个一个字节的读取,遇到\r\n就表示一条消息读取完毕.

阅读 4.5k
3 个回答

所有的数据是当做字节流输入输出,需要应用程序切割或粘包。

不是read么?我还以为是别的什么呢。去查read接口文档吧

ssize_t read(int fd, void *buf, size_t count);

On success, the number of bytes read is returned (zero indicates end of file),It is not an error if this number is smaller than the number of bytes requested; this may happen for example because fewer bytes

   are  actually  available  right  now
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进