MCPcopy Index your code
hub / github.com/F-Stack/f-stack / main

Function main

example/main_epoll.c:105–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105int main(int argc, char * argv[])
106{
107 ff_init(argc, argv);
108
109 sockfd = ff_socket(AF_INET, SOCK_STREAM, 0);
110 ff_log(FF_LOG_DEBUG, FF_LOGTYPE_FSTACK_APP, "sockfd:%d\n", sockfd);
111 if (sockfd < 0) {
112 ff_log(FF_LOG_ERR, FF_LOGTYPE_FSTACK_APP, "ff_socket failed\n");
113 exit(1);
114 }
115
116 int on = 1;
117 ff_ioctl(sockfd, FIONBIO, &on);
118
119 struct sockaddr_in my_addr;
120 bzero(&my_addr, sizeof(my_addr));
121 my_addr.sin_family = AF_INET;
122 my_addr.sin_port = htons(80);
123 my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
124
125 int ret = ff_bind(sockfd, (struct linux_sockaddr *)&my_addr, sizeof(my_addr));
126 if (ret < 0) {
127 ff_log(FF_LOG_ERR, FF_LOGTYPE_FSTACK_APP, "ff_bind failed\n");
128 exit(1);
129 }
130
131 ret = ff_listen(sockfd, MAX_EVENTS);
132 if (ret < 0) {
133 ff_log(FF_LOG_ERR, FF_LOGTYPE_FSTACK_APP, "ff_listen failed\n");
134 exit(1);
135 }
136
137 assert((epfd = ff_epoll_create(0)) > 0);
138 ev.data.fd = sockfd;
139 ev.events = EPOLLIN;
140 ff_epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
141 ff_run(loop, NULL);
142 return 0;
143}

Callers

nothing calls this directly

Calls 10

ff_initFunction · 0.85
ff_logFunction · 0.85
ff_ioctlFunction · 0.85
bzeroFunction · 0.85
ff_bindFunction · 0.85
ff_listenFunction · 0.85
ff_epoll_createFunction · 0.85
ff_epoll_ctlFunction · 0.85
ff_runFunction · 0.85
ff_socketFunction · 0.50

Tested by

no test coverage detected