Skip to content

Commit c0a9f53

Browse files
committed
Fixed #705. While Adding -DNDEBUG flag will cause the helloworld example
to crash. Because `assert((kq = ff_kqueue()) > 0);` was be ignored and nevents used usigned type.
1 parent c35e5fd commit c0a9f53

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

example/main.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int sockfd;
2525
int sockfd6;
2626
#endif
2727

28-
char html[] =
28+
char html[] =
2929
"HTTP/1.1 200 OK\r\n"
3030
"Server: F-Stack\r\n"
3131
"Date: Sat, 25 Feb 2017 09:26:33 GMT\r\n"
@@ -60,8 +60,14 @@ char html[] =
6060
int loop(void *arg)
6161
{
6262
/* Wait for events to happen */
63-
unsigned nevents = ff_kevent(kq, NULL, 0, events, MAX_EVENTS, NULL);
64-
unsigned i;
63+
int nevents = ff_kevent(kq, NULL, 0, events, MAX_EVENTS, NULL);
64+
int i;
65+
66+
if (nevents < 0) {
67+
printf("ff_kevent failed:%d, %s\n", errno,
68+
strerror(errno));
69+
return -1;
70+
}
6571

6672
for (i = 0; i < nevents; ++i) {
6773
struct kevent event = events[i];
@@ -111,7 +117,11 @@ int main(int argc, char * argv[])
111117
{
112118
ff_init(argc, argv);
113119

114-
assert((kq = ff_kqueue()) > 0);
120+
kq = ff_kqueue();
121+
if (kq < 0) {
122+
printf("ff_kqueue failed, errno:%d, %s\n", errno, strerror(errno));
123+
exit(1);
124+
}
115125

116126
sockfd = ff_socket(AF_INET, SOCK_STREAM, 0);
117127
if (sockfd < 0) {
@@ -167,7 +177,11 @@ int main(int argc, char * argv[])
167177
}
168178

169179
EV_SET(&kevSet, sockfd6, EVFILT_READ, EV_ADD, 0, MAX_EVENTS, NULL);
170-
ff_kevent(kq, &kevSet, 1, NULL, 0, NULL);
180+
ret = ff_kevent(kq, &kevSet, 1, NULL, 0, NULL);
181+
if (ret < 0) {
182+
printf("ff_kevent failed:%d, %s\n", errno, strerror(errno));
183+
exit(1);
184+
}
171185
#endif
172186

173187
ff_run(loop, NULL);

0 commit comments

Comments
 (0)