MCPcopy Create free account
hub / github.com/acl-dev/acl / run_server

Function run_server

lib_protocol/samples/httpd/main.c:152–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152static void run_server(const char *addr)
153{
154 ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128);
155 acl_pthread_pool_t *pool;
156 CONN *conn;
157 acl_pthread_t tid;
158 acl_pthread_attr_t attr;
159 ACL_VSTREAM *client;
160
161 if (sstream == NULL) {
162 acl_msg_error("listen %s error(%s)", addr, acl_last_serror());
163 return;
164 }
165
166 pthread_attr_init(&attr);
167 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
168
169 printf("listening on %s ...\n", addr);
170 pool = acl_thread_pool_create(10, 10);
171 while (1) {
172 acl_mem_slice_delay_destroy();
173 if (acl_read_wait(ACL_VSTREAM_SOCK(sstream), 5) == -1)
174 continue;
175 client = acl_vstream_accept(sstream, NULL, 0);
176 if (client == NULL) {
177 acl_msg_error("accept error(%s)", acl_last_serror());
178 break;
179 }
180 acl_tcp_set_nodelay(ACL_VSTREAM_SOCK(client));
181 conn = acl_mycalloc(1, sizeof(CONN));
182 conn->stream = client;
183
184 if (0)
185 thread_run(conn);
186 else if (1)
187 acl_pthread_create(&tid, &attr, thread_main, conn);
188 else
189 acl_pthread_pool_add(pool, thread_run, conn);
190 }
191
192 acl_vstream_close(sstream);
193}
194
195static void run_client(const char *addr, const char *filename)
196{

Callers 1

mainFunction · 0.70

Calls 11

acl_vstream_listenFunction · 0.85
acl_msg_errorFunction · 0.85
acl_last_serrorFunction · 0.85
acl_thread_pool_createFunction · 0.85
acl_read_waitFunction · 0.85
acl_vstream_acceptFunction · 0.85
acl_tcp_set_nodelayFunction · 0.85
acl_pthread_createFunction · 0.85
acl_vstream_closeFunction · 0.85
thread_runFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…