MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / duk_trans_socket_init

Function duk_trans_socket_init

Source/Utils/duk_trans_socket_windows.cpp:82–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 */
81
82void duk_trans_socket_init(void) {
83 WSADATA wsa_data;
84 struct addrinfo hints;
85 struct addrinfo *result = NULL;
86 int rc;
87
88 memset((void *) &wsa_data, 0, sizeof(wsa_data));
89 memset((void *) &hints, 0, sizeof(hints));
90
91 rc = WSAStartup(MAKEWORD(2, 2), &wsa_data);
92 if (rc != 0) {
93 fprintf(stderr, "%s: WSAStartup() failed: %d\n", __FILE__, rc);
94 fflush(stderr);
95 goto fail;
96 }
97 wsa_inited = 1;
98
99 hints.ai_family = AF_UNSPEC;
100 hints.ai_socktype = SOCK_STREAM;
101 hints.ai_protocol = IPPROTO_TCP;
102 hints.ai_flags = AI_PASSIVE;
103
104 rc = getaddrinfo(DUK_DEBUG_ADDRESS, DUK__STRINGIFY(DUK_DEBUG_PORT), &hints, &result);
105 if (rc != 0) {
106 fprintf(stderr, "%s: getaddrinfo() failed: %d\n", __FILE__, rc);
107 fflush(stderr);
108 goto fail;
109 }
110
111 server_sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
112 if (server_sock == INVALID_SOCKET) {
113 fprintf(stderr, "%s: socket() failed with error: %ld\n",
114 __FILE__, (long) WSAGetLastError());
115 fflush(stderr);
116 goto fail;
117 }
118
119 rc = bind(server_sock, result->ai_addr, (int) result->ai_addrlen);
120 if (rc == SOCKET_ERROR) {
121 fprintf(stderr, "%s: bind() failed with error: %ld\n",
122 __FILE__, (long) WSAGetLastError());
123 fflush(stderr);
124 goto fail;
125 }
126
127 rc = listen(server_sock, SOMAXCONN);
128 if (rc == SOCKET_ERROR) {
129 fprintf(stderr, "%s: listen() failed with error: %ld\n",
130 __FILE__, (long) WSAGetLastError());
131 fflush(stderr);
132 goto fail;
133 }
134
135 if (result != NULL) {
136 freeaddrinfo(result);
137 result = NULL;
138 }
139 return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected