socket_new : udp:bool -> 'socket Create a new socket, TCP or UDP **/
| 172 | <doc>Create a new socket, TCP or UDP</doc> |
| 173 | **/ |
| 174 | Dynamic _hx_std_socket_new( bool udp, bool ipv6 ) |
| 175 | { |
| 176 | if (!socketType) |
| 177 | socketType = hxcpp_alloc_kind(); |
| 178 | |
| 179 | SOCKET s; |
| 180 | int family = ipv6 ? AF_INET6 : AF_INET; |
| 181 | if( udp ) |
| 182 | s = socket(family,SOCK_DGRAM,0); |
| 183 | else |
| 184 | s = socket(family,SOCK_STREAM,0); |
| 185 | |
| 186 | if( s == INVALID_SOCKET ) |
| 187 | return null(); |
| 188 | |
| 189 | #ifdef NEKO_MAC |
| 190 | int set = 1; |
| 191 | setsockopt(s,SOL_SOCKET,SO_NOSIGPIPE,(void *)&set, sizeof(int)); |
| 192 | #endif |
| 193 | |
| 194 | #ifdef NEKO_POSIX |
| 195 | // we don't want sockets to be inherited in case of exec |
| 196 | int old = fcntl(s,F_GETFD,0); |
| 197 | if( old >= 0 ) fcntl(s,F_SETFD,old|FD_CLOEXEC); |
| 198 | #endif |
| 199 | |
| 200 | SocketWrapper *wrap = new SocketWrapper(); |
| 201 | wrap->socket = s; |
| 202 | return wrap; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | socket_close : 'socket -> void |
nothing calls this directly
no test coverage detected