lpereira / lwan

Experimental, scalable, high performance HTTP server
https://lwan.ws
GNU General Public License v2.0
5.94k stars 548 forks source link

Error when building on Mac OS X #128

Closed kazzkiq closed 8 years ago

kazzkiq commented 8 years ago

When I run the make command from readme.md tutorial, I get this message:

/Users/kazzkiq/lwan/common/lwan.c:660:25: warning: implicit declaration of
      function 'accept4' is invalid in C99 [-Wimplicit-function-declaration]
        int client_fd = accept4((int)main_socket, NULL, NULL, SOCK_NONBL...
                        ^
/Users/kazzkiq/lwan/common/lwan.c:660:63: error: use of undeclared identifier
      'SOCK_NONBLOCK'
        int client_fd = accept4((int)main_socket, NULL, NULL, SOCK_NONBL...
                                                              ^
1 warning and 1 error generated.
make[2]: *** [common/CMakeFiles/lwan-common.dir/lwan.c.o] Error 1
make[1]: *** [common/CMakeFiles/lwan-common.dir/all] Error 2
make: *** [all] Error 2

Cmake v 3.4.1 Python v 2.7.10

The commands I used to run LWAN were:

git clone git://github.com/lpereira/lwan
cd lwan
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make

Did I miss any step?

lpereira commented 8 years ago

Lwan is unfortunately not compatible with OS X. I don't own a Mac, so I can't support it myself.

lpereira commented 8 years ago

Help is appreciated to make it work on OS X, though. Could you please try changing the call to accept4() to a call to accept() (just omit the last parameter) and report if it works or not?

Lwan should build -- although it isn't working -- on FreeBSD, which OS X is quite similar to. So it shouldn't be too much work to at least get it building on a Mac.

kazzkiq commented 8 years ago

@lpereira I've tried to replace accept4() by accept() and got this error:

[  2%] Built target generate_mime_types_table
Scanning dependencies of target lwan-common
[  5%] Building C object common/CMakeFiles/lwan-common.dir/lwan.c.o
[  7%] Building C object common/CMakeFiles/lwan-common.dir/lwan-cache.c.o
/Users/kazzkiq/lwan/common/lwan-cache.c:81:8: error: unknown type name
      'clockid_t'; did you mean 'clock_t'?
static clockid_t detect_fastest_monotonic_clock(void)
       ^~~~~~~~~
       clock_t
/usr/include/sys/_types/_clock_t.h:30:33: note: 'clock_t' declared here
typedef __darwin_clock_t        clock_t;
                                ^
/Users/kazzkiq/lwan/common/lwan-cache.c:89:12: error: use of undeclared
      identifier 'CLOCK_MONOTONIC'
    return CLOCK_MONOTONIC;
           ^
/Users/kazzkiq/lwan/common/lwan-cache.c:92:67: warning: unused parameter 'cache'
      [-Wunused-parameter]
static ALWAYS_INLINE void clock_monotonic_gettime(struct cache_t *cache,
                                                                  ^
1 warning and 2 errors generated.
make[2]: *** [common/CMakeFiles/lwan-common.dir/lwan-cache.c.o] Error 1
make[1]: *** [common/CMakeFiles/lwan-common.dir/all] Error 2
make: *** [all] Error 2

Doing some further research it seems OSX doesn't have POSIX clock_* implemented, that would explain those errors.

As I have a very basic knowledge on C development I can't argue about further solutions for this issue. But on an overlook it seems the errors happening on OSX are just due to different API implementations and thus should not be a big deal to fix in the future (hopefully).

lampmanyao commented 8 years ago

I am working on this, except the coro_swapcontext() routine.

lampmanyao commented 8 years ago

That's a lot of work to do. I can build lwan on OSX now. But I got a segment fault when I run lwan without lwan.conf and access 127.0.0.1:8080. Even it can't be debug with lldb. That's another problem, I run lwan with the default lwan.conf, I got an errer: Error on config file "lwan.conf", line 21: Invalid section name or module not found: serve_files. Anyway, I am still working on this. ;)

lpereira commented 8 years ago

Pretty nice, @LampmanYao! That looks like where I am while trying to run it under FreeBSD: it runs, but segfaults after a few requests. Sometimes it's the first request, sometimes it takes a few dozen requests.

Sometimes prints requests with an "UNKNOWN" method are printed, which is quite unexpected; are you seeing this as well?

lampmanyao commented 8 years ago

@lpereira It is not the same problem. The segfaults i have fixed, but now, i got a Bus error (10) and all thread are stopped by signal SIGSTOP.

lampmanyao commented 8 years ago

@lpereira it's the exactly segfault like you said. Do you figure it out? @kazzkiq I will push the patch to my Resp, maybe you can solve this problem.

lpereira commented 8 years ago

I haven't had time to investigate any further, unfortunately. Please make a PR with the patch to build it on OS X, maybe someone will be able to take a shot at debugging this as well. Thanks again!

lpereira commented 8 years ago

I'm closing this issue as Lwan is building on OS X now. It also has a OS X build bot so I'm notified in case something breaks. Feel free to reopen the issue or create a new one.