Debian Codegraph @

terps/tads/tads3/test/test_osnet_2.cpp

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "t3std.h"
5 #include "os.h"
6 #include "osifc.h"
7 #include "osifcnet.h"
8 #include "vmnet.h"
9 #include "vmrun.h"
10
11
12 /* dummy entrypoint for HTTPRequest intrinsic class construction */
13 vm_obj_id_t TadsHttpRequest::prep_event_obj(VMG_ int *, int *)
14 {
15 return VM_INVALID_OBJ;
16 }
17
18 /* dummy entrypoints for exception throwing from vmnet.cpp */
19 void CVmRun::push_string(VMG_ const char *, size_t) { }
20 void CVmRun::push_stringf(VMG_ const char *, ...) { }
21 void CVmRun::throw_new_rtesub(VMG_ vm_obj_id_t, uint, int) { }
22
23
24 /* main program entrypoint */
25 int main(int argc, char **argv)
26 {
27 /* initialize the network/thread package */
28 os_net_init(0);
29
30 /* create the incoming request queue */
31 TadsMessageQueue *req_queue = new TadsMessageQueue(0);
32
33 /* create the http listener */
34 TadsHttpListenerThread *ht = new TadsHttpListenerThread(
35 VM_INVALID_OBJ, req_queue, 65535);
36 TadsListener *l = TadsListener::launch("localhost", 0, ht);
37
38 int port;
39 char *ip;
40 if (ht->get_local_addr(ip, port))
41 {
42 printf("http listener on %s port %d\n"
43 "http://%s:%d/status?psw=%s\n\n",
44 ip, port,
45 ip, port, ht->get_password());
46 lib_free_str(ip);
47 }
48
49 /* wait until done */
50 printf("Enter commands - Q=quit\n");
51 for (;;)
52 {
53 char buf[128];
54 if (fgets(buf, sizeof(buf), stdin) == 0)
55 break;
56
57 if (buf[0] == 'q' || buf[0] == 'Q')
58 break;
59
60 printf("Unrecognized command\n");
61 }
62
63 /* shut down the http listener and wait for it to finish */
64 l->shutdown();
65 ht->wait();
66
67 /* done with the listener */
68 l->release_ref();
69
70 /* clean up the network/thread package */
71 os_net_cleanup();
72 }
73