有没有办法刷新 POSIX 套接字? [英] Is there a way to flush a POSIX socket?

查看:24
本文介绍了有没有办法刷新 POSIX 套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有将 POSIX 套接字的传输端一直刷新到远程端的标准调用,或者这是否需要作为用户级协议的一部分来实现?我环顾了通常的标题,但找不到任何东西.

Is there a standard call for flushing the transmit side of a POSIX socket all the way through to the remote end or does this need to be implemented as part of the user level protocol? I looked around the usual headers but couldn't find anything.

推荐答案

对于 Unix 域套接字,您可以使用 fflush(),但我认为您可能指的是网络套接字.真的没有冲洗这些的概念.最接近的事情是:

For Unix-domain sockets, you can use fflush(), but I'm thinking you probably mean network sockets. There isn't really a concept of flushing those. The closest things are:

  1. 在会话结束时,调用 shutdown(sock, SHUT_WR) 以关闭对套接字的写入.

  1. At the end of your session, calling shutdown(sock, SHUT_WR) to close out writes on the socket.

在 TCP 套接字上,使用 sockopt TCP_NODELAY 禁用 Nagle 算法,这通常是一个糟糕的想法,它不会可靠地执行您想要的操作,即使它似乎在初步调查.

On TCP sockets, disabling the Nagle algorithm with sockopt TCP_NODELAY, which is generally a terrible idea that will not reliably do what you want, even if it seems to take care of it on initial investigation.

很可能在用户协议级别处理任何需要刷新"的问题都是正确的.

It's very likely that handling whatever issue is calling for a 'flush' at the user protocol level is going to be the right thing.

这篇关于有没有办法刷新 POSIX 套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆