shigeki / uv_webserver

Hello World WebServer with libuv
23 stars 9 forks source link

osx compile errors #1

Open stuta opened 11 years ago

stuta commented 11 years ago

Hello. Quick OSX test:

webserver.c:94: warning: passing argument 3 of ‘uv_read_start’ from incompatible pointer type ld: library not found for -lrt collect2: ld returned 1 exit status

Remove -lrt fom makefile in osx.

shigeki commented 11 years ago

@stuta Thanks for your build report on OSX. I'm afraid I don't have a Mac but I've just updated Makefile by looking at libuv/Makefile to add build options for OSX. I'm not sure if it works. Please try it.

stuta commented 11 years ago

I finally got it to work after building libuv with xcode and changing makefile.

gcc -o webserver webserver.c libuv/libuv.a http-parser/http_parser.o -lpthread -framework CoreServices

webserver.c: In function ‘on_connected’: webserver.c:94: warning: passing argument 3 of ‘uv_read_start’ from incompatible pointer type

stuta commented 11 years ago

It works in browser, but with:

ab -c10 -n100 http://127.0.0.1:8000/

Segmentation fault: 11

with your makefile: ./webserver -bash: ./webserver: cannot execute binary file

file webserver webserver: Mach-O 64-bit dynamically linked shared library x86_64

remove -dynamiclib

stuta commented 11 years ago

OK, now it works better with ab until I get error:

ab -c10 -n100 http://127.0.0.1:8000/ Requests per second: 8517.89 #/sec

b -c10 -n10000 http://127.0.0.1:8000/

Assertion failed: (!(handle->flags & (UV_CLOSING | UV_CLOSED))), function uv_close, file src/unix/core.c, line 75. parse errorparse errorparse errorparse errorparse errorparse errorparse errorparse errorparse errorparse errorAbort trap: 6

shigeki commented 11 years ago

ab -c10 -n10000 http://127.0.0.1:8000/ works on my Linux. Hmm. There seems something wrong on MacOS.

stuta commented 11 years ago

Maybe you need to increase call amounts or check this compile warning:

webserver.c:94: warning: passing argument 3 of ‘uv_read_start’ from incompatible pointer type

stuta commented 11 years ago

No I don't get any more charshes. Also fflush is needed to get errors to show.

static void on_read(uv_stream_t* handle, int nread, uv_buf_t buf) {
  client_t* client = handle->data;
  size_t parsed;
  static int errNum = 0;

  if (nread >= 0) {
    /* parse http */

    parsed = http_parser_execute(&client->parser,
                                 &settings,
                                 buf.base,
                                 nread);

    if (parsed < nread) {
      errNum++;
      fprintf(stderr, "parse error %d.\n", errNum);
      fflush(stdout);
      // uv_close((uv_handle_t*)handle, on_close); // crash in OSX
    }

  } else { 
    uv_err_t err = uv_last_error(handle->loop);

    if (err.code == UV_EOF) {
      /* do nothing */
    } else {
      fprintf(stderr, "read: %s\n", uv_strerror(err));
      fflush(stdout);
    }

    uv_close((uv_handle_t*)handle, on_close);
  }

  free(buf.base);
}
shigeki commented 11 years ago

@stuta Thanks for the report. I'm glad to hear that it's working well on MacOS. I will check why uv_close() cause crash.