int main(void) { struct schedule * S = coroutine_open(); test(S); coroutine_close(S); return 0; }
int main() { int listenfd, optval = 1; int i; int port = 9500; struct sockaddr_in serveraddr; listenfd = socket(AF_INET, SOCK_STREAM, 0); setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval , sizeof(int)); bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); serveraddr.sin_port = htons((unsigned short)port); bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); listen(listenfd, 1024); make_socket_non_blocking(listenfd); struct schedule * S = coroutine_open(); printf("start..\n"); int co1 = coroutine_new(S, acceptfun, (void *)&listenfd); printf("%d\n", S->cap); printf("%d\n", co1); for(i = 0; i < S->cap; i++) { if(coroutine_status(S, i)) { coroutine_resume(S,i); } if(i == S->cap - 1) i = -1; } coroutine_close(S); close(listenfd); return 0; }