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

Function main

adapter/syscall/main_stack_epoll.c:139–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139int main(int argc, char * argv[])
140{
141 int i, worker_num = 1;
142
143 signal(SIGINT, sig_term);
144 signal(SIGTERM, sig_term);
145
146 sockfd = socket(AF_INET, SOCK_STREAM, 0);
147 printf("sockfd:%d\n", sockfd);
148 if (sockfd < 0) {
149 printf("ff_socket failed\n");
150 return -1;
151 }
152
153 int on = 1;
154 ioctl(sockfd, FIONBIO, &on);
155
156 struct sockaddr_in my_addr;
157 bzero(&my_addr, sizeof(my_addr));
158 my_addr.sin_family = AF_INET;
159 my_addr.sin_port = htons(80);
160 my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
161
162 int ret = bind(sockfd, (const struct sockaddr *)&my_addr, sizeof(my_addr));
163 if (ret < 0) {
164 printf("ff_bind failed\n");
165 close(sockfd);
166 return -1;
167 }
168
169 ret = listen(sockfd, MAX_EVENTS);
170 if (ret < 0) {
171 printf("ff_listen failed\n");
172 close(sockfd);
173 return -1;
174 }
175
176 epfd = epoll_create(512);
177 printf("epfd:%d\n", epfd);
178 if (epfd <= 0) {
179 printf("ff_epoll_create failed, errno:%d, %s\n",
180 errno, strerror(errno));
181 close(sockfd);
182 return -1;
183 }
184
185 ev.data.fd = sockfd;
186 ev.events = EPOLLIN;
187 ret = epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
188 if (ret < 0) {
189 printf("ff_listen failed\n");
190 close(epfd);
191 close(sockfd);
192 return -1;
193 }
194
195 for (i = 0; i < worker_num; i++) {
196 if(pthread_create(&hworker[i], NULL, loop, (void *)&i) < 0) {

Callers

nothing calls this directly

Calls 10

bzeroFunction · 0.85
epoll_createFunction · 0.85
epoll_ctlFunction · 0.85
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