• FD_WRITE是如何触发的?


    The FD_WRITE network event is handled slightly differently. An FD_WRITE network event is recorded when a socket is first connected with connect/WSAConnect or accepted with accept/WSAAccept, and then after a send fails with WSAEWOULDBLOCK and buffer space becomes available. Therefore, an application can assume that sends are possible starting from the first FD_WRITE network event setting and lasting until a send returns WSAEWOULDBLOCK. After such a failure the application will find out that sends are again possible when an FD_WRITE network event is recorded and the associated event object is set


    FD_WRITE事件只有在以下三种情况下才会触发
    ①client 通过connect(WSAConnect)首次和server建立连接时,在client端会触发FD_WRITE事件
    ②server通过accept(WSAAccept)接受client连接请求时,在server端会触发FD_WRITE事件
    ③send(WSASend)/sendto(WSASendTo)发送失败返回WSAEWOULDBLOCK,并且当缓冲区有可用空间时,则会触发FD_WRITE事件
    ①②其实是同一种情况,在第一次建立连接时,C/S端都会触发一个FD_WRITE事件。
    主要是③这种情况:send出去的数据其实都先存在winsock的发送缓冲区中,然后才发送出去,如果缓冲区满了,那么再调用send(WSASend,sendto,WSASendTo)的话,就会返回一个 WSAEWOULDBLOCK的错误码,接下来随着发送缓冲区中的数据被发送出去,缓冲区中出现可用空间时,一个 FD_WRITE 事件才会被触发,这里比较容易混淆的是 FD_WRITE 触发的前提是 缓冲区要先被充满然后随着数据的发送又出现可用空间,而不是缓冲区中有可用空间
    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    office 365 sharepoint online 学习资料
    NPOI 导入 导出 Excel
    800703fa Illegal operation attempted on a registry key that has been marked for deletion
    js 获取身份证号码出生日期,籍贯等信息
    直接在浏览器中修改网页内容
    asp.net 按指定模板导出word,pdf
    StackPanel在增加控件的问题
    解决iOS工程被Xcode识别成Mac工程的问题
    Swift之异常处理
    Swift中的协议和闭包
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616380.html
Copyright © 2020-2023  润新知