• HawkNL 源码剖析


     1 void sock_Close(NLsocket socket)
    2 {
    3 nl_socket_t *sock = nlSockets[socket];
    4 struct ip_mreq mreq;
    5
    6 if(sock->type == NL_UDP_MULTICAST)
    7 {
    8 /* leave the multicast group */
    9 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)&sock->addressout)->sin_addr.s_addr;
    10 mreq.imr_interface.s_addr = bindaddress;
    11
    12 (void)setsockopt((SOCKET)sock->realsocket, IPPROTO_IP, IP_DROP_MEMBERSHIP,
    13 (char *)&mreq, (int)sizeof(mreq));
    14 }
    15 if(sock->type == NL_RELIABLE_PACKETS)
    16 {
    17 /* check for unsent data */
    18 if(sock->sendlen > 0)
    19 {
    20 int tries = 200;
    21
    22 /* 200 * 50 ms = up to a 10 second delay to allow data to be sent */
    23 while(tries-- > 0 && sock->sendlen > 0)
    24 {
    25 htThreadSleep(50);
    26 }
    27 }
    28 sock_DeleteSocket(socket);
    29 }
    30 if((sock->type == NL_RELIABLE_PACKETS || sock->type == NL_RELIABLE) && sock->listen == NL_FALSE)
    31 {
    32 struct linger l = {1, 10};//延迟10s
    33
    34 (void)setsockopt((SOCKET)sock->realsocket, SOL_SOCKET, SO_LINGER, (const char *)&l, (int)sizeof(l));
    35 (void)shutdown((SOCKET)sock->realsocket, SD_RECEIVE);
    36 }
    37 else
    38 {
    39 (void)shutdown((SOCKET)sock->realsocket, SD_BOTH);
    40 }
    41 (void)closesocket((SOCKET)sock->realsocket);
    42 }
    本文版权归作者 kanego 和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    VBA_headers_mapping
    pandas_知识总结_基础
    python_super()及继承顺序
    python_端口扫描
    python_socket登陆验证_明文
    python_sys.argv的使用
    python_os_shutil_获取文件夹下所有文件的大小
    python_面向对象_组合
    魔术球问题 【网络流24题】【建图技巧】
    牛客&科大讯飞杯&SHU、L动物森友会【二分】【网络流】
  • 原文地址:https://www.cnblogs.com/kanego/p/2436408.html
Copyright © 2020-2023  润新知