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

Function main

adapter/syscall/main_stack.c:148–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148int main(int argc, char * argv[])
149{
150 signal(SIGINT, sig_term);
151 signal(SIGTERM, sig_term);
152
153 sockfd = socket(AF_INET, SOCK_STREAM, 0);
154 printf("sockfd:%d\n", sockfd);
155 if (sockfd < 0) {
156 printf("ff_socket failed, sockfd:%d, errno:%d, %s\n", sockfd, errno, strerror(errno));
157 return -1;;
158 }
159
160 /* Set non blocking */
161 int on = 1;
162 ioctl(sockfd, FIONBIO, &on);
163
164 struct sockaddr_in my_addr;
165 bzero(&my_addr, sizeof(my_addr));
166 my_addr.sin_family = AF_INET;
167 my_addr.sin_port = htons(80);
168 my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
169
170 int ret = bind(sockfd, (const struct sockaddr *)&my_addr, sizeof(my_addr));
171 if (ret < 0) {
172 printf("ff_bind failed, sockfd:%d, errno:%d, %s\n", sockfd, errno, strerror(errno));
173 close(sockfd);
174 return -1;
175 }
176
177 ret = listen(sockfd, MAX_EVENTS);
178 if (ret < 0) {
179 printf("ff_listen failed, sockfd:%d, errno:%d, %s\n", sockfd, errno, strerror(errno));
180 close(sockfd);
181 return -1;
182 }
183
184 kq = kqueue();
185 printf("kq:%d\n", kq);
186 if (kq < 0) {
187 printf("ff_kqueue failed, errno:%d, %s\n", errno, strerror(errno));
188 close(sockfd);
189 return -1;
190 }
191
192 EV_SET(&kevSet, sockfd, EVFILT_READ, EV_ADD, 0, MAX_EVENTS, NULL);
193 /* Update kqueue */
194 ret = kevent(kq, &kevSet, 1, NULL, 0, &timeout);
195 if (ret < 0) {
196 printf("kevent failed\n");
197 close(kq);
198 close(sockfd);
199 return -1;
200 }
201
202 if(pthread_create(&hworker, NULL, loop, NULL) < 0) {
203 printf("create loop thread failed., errno:%d/%s\n",
204 errno, strerror(errno));
205 close(kq);

Callers

nothing calls this directly

Calls 10

bzeroFunction · 0.85
kqueueFunction · 0.70
keventClass · 0.70
socketFunction · 0.50
printfFunction · 0.50
ioctlFunction · 0.50
bindFunction · 0.50
closeFunction · 0.50
listenFunction · 0.50
pthread_createFunction · 0.50

Tested by

no test coverage detected