| 173 | } |
| 174 | |
| 175 | static int CreateTcpSocket(const unsigned short shPort /* = 0 */,const char *pszIP /* = "*" */,bool bReuse /* = false */) |
| 176 | { |
| 177 | int fd = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); |
| 178 | if( fd >= 0 ) |
| 179 | { |
| 180 | if(shPort != 0) |
| 181 | { |
| 182 | if(bReuse) |
| 183 | { |
| 184 | int nReuseAddr = 1; |
| 185 | setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&nReuseAddr,sizeof(nReuseAddr)); |
| 186 | } |
| 187 | struct sockaddr_in addr ; |
| 188 | SetAddr(pszIP,shPort,addr); |
| 189 | int ret = bind(fd,(struct sockaddr*)&addr,sizeof(addr)); |
| 190 | if( ret != 0) |
| 191 | { |
| 192 | close(fd); |
| 193 | return -1; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | return fd; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | int main(int argc,char *argv[]) |
no test coverage detected