#include #include #include #include #include static int handler (TSCont contp, TSEvent event, void *edata __attribute__((unused))) { if (event == TS_EVENT_IMMEDIATE) { struct sockaddr_in ip; int ret; memset(&ip, 0, sizeof(struct sockaddr_in)); ip.sin_family = AF_INET; ip.sin_port = htons(9999); ret = inet_pton(AF_INET, "127.0.0.1", &ip.sin_addr); assert( ret == 1 ); TSAction actionp = TSNetConnect (contp, (struct sockaddr const*) &ip); if (!TSActionDone (actionp)) { TSContDataSet (contp, actionp); } else { /* We've already been called back... */ return 0; } } else if (event == TS_EVENT_NET_CONNECT) { /* Net connection succeeded */ TSContDataSet (contp, NULL); return 0; } else if (event == TS_EVENT_NET_CONNECT_FAILED) { /* Net connection failed */ TSContDataSet (contp, NULL); return 0; } return 0; } void TSPluginInit (int argc __attribute__((unused)), const char *argv[] __attribute__((unused))) { TSCont contp; contp = TSContCreate (handler, TSMutexCreate ()); /* We don't want to call things out of TSPluginInit directly since it's called before the rest of the system is initialized. We'll simply schedule an event on the continuation to occur as soon as the rest of the system is started up. */ TSContSchedule (contp, 0, TS_THREAD_POOL_DEFAULT); }