MCPcopy Create free account
hub / github.com/F-Stack/f-stack / loop

Function loop

adapter/syscall/main_stack_thread_socket.c:75–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void *loop(void *arg)
76{
77 /* kevent set */
78 struct kevent kevSet;
79 /* events */
80 struct kevent events[MAX_EVENTS];
81 /* kq */
82 int kq;
83 int sockfd;
84
85 int thread_id;
86
87 thread_id = *(int *)arg;
88 printf("start thread %d\n", thread_id);
89
90 sockfd = socket(AF_INET, SOCK_STREAM, 0);
91 printf("thread %d, sockfd:%d\n", thread_id, sockfd);
92 if (sockfd < 0) {
93 printf("thread %d, ff_socket failed\n", thread_id);
94 pthread_spin_unlock(&worker_lock);
95 return NULL;
96 }
97
98 /* socket will init adapter,so unlock after socket */
99 pthread_spin_unlock(&worker_lock);
100
101 int on = 1;
102 ioctl(sockfd, FIONBIO, &on);
103
104 struct sockaddr_in my_addr;
105 bzero(&my_addr, sizeof(my_addr));
106 my_addr.sin_family = AF_INET;
107 my_addr.sin_port = htons(80);
108 my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
109
110 int ret = bind(sockfd, (const struct sockaddr *)&my_addr, sizeof(my_addr));
111 if (ret < 0) {
112 printf("thread %d, ff_bind failed\n", thread_id);
113 close(sockfd);
114 return NULL;
115 }
116
117 ret = listen(sockfd, MAX_EVENTS);
118 if (ret < 0) {
119 printf("thread %d, ff_listen failed\n", thread_id);
120 close(sockfd);
121 return NULL;
122 }
123
124
125 kq = kqueue();
126 printf("thread %d, kq:%d\n", thread_id, kq);
127 if (kq < 0) {
128 printf("thread %d, ff_kqueue failed, errno:%d, %s\n", thread_id, errno, strerror(errno));
129 close(sockfd);
130 return NULL;
131 }
132

Callers

nothing calls this directly

Calls 12

bzeroFunction · 0.85
kqueueFunction · 0.70
keventClass · 0.70
printfFunction · 0.50
socketFunction · 0.50
ioctlFunction · 0.50
bindFunction · 0.50
closeFunction · 0.50
listenFunction · 0.50
acceptFunction · 0.50
readFunction · 0.50
writeFunction · 0.50

Tested by

no test coverage detected