| 82 | } |
| 83 | |
| 84 | static int CreateTcpSocket(const unsigned short shPort = 0 ,const char *pszIP = "*" ,bool bReuse = false ) |
| 85 | { |
| 86 | int fd = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); |
| 87 | if( fd >= 0 ) |
| 88 | { |
| 89 | if(shPort != 0) |
| 90 | { |
| 91 | if(bReuse) |
| 92 | { |
| 93 | int nReuseAddr = 1; |
| 94 | setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&nReuseAddr,sizeof(nReuseAddr)); |
| 95 | } |
| 96 | struct sockaddr_in addr ; |
| 97 | SetAddr(pszIP,shPort,addr); |
| 98 | int ret = bind(fd,(struct sockaddr*)&addr,sizeof(addr)); |
| 99 | if( ret != 0) |
| 100 | { |
| 101 | close(fd); |
| 102 | return -1; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return fd; |
| 107 | } |
| 108 | |
| 109 | static void *poll_routine( void *arg ) |
| 110 | { |
no test coverage detected