dpull / skynet-mingw

对skynet无任何改动的windows版
http://blog.dpull.com/post/2015-11-08-skynet_mingw
MIT License
306 stars 127 forks source link

windows版本listen同一端口不报错 #6

Closed heyilin416 closed 7 years ago

dpull commented 7 years ago

因为socket_server.c 中 bind端口前将socket设置为了SO_REUSEADDR,所以这是功能。

  1. 同一进程中,listen同一端口是错误的设计。
  2. 如果不设置该标志, 当服务器重启时,可能端口会因占用导致无法正常启动服务器。

SO_REUSEADDR

          Indicates that the rules used in validating addresses supplied
          in a bind(2) call should allow reuse of local addresses.  For
          AF_INET sockets this means that a socket may bind, except when
          there is an active listening socket bound to the address.
          When the listening socket is bound to INADDR_ANY with a
          specific port then it is not possible to bind to this port for
          any local address.  Argument is an integer boolean flag.