hello all
i try to create loogger from within the libuv server ( simple ) followed 
the examples i barely found in the net 
i do manage to write to file but when i try to write to the log from some 
different place in the code im getting exception .
this is what i have :

const char* logfile = "wsserver.log";
char buf[] = "Server Started!\n";
uv_fs_t open_req;
uv_fs_t write_req;
uv_fs_t close_req;


int resultFD;


void open_cb(uv_fs_t* req);
void write_cb(uv_fs_t* req);
void close_cb(uv_fs_t* req);


void open_cb(uv_fs_t* req) {
 resultFD = req->result;
 const uv_buf_t buf1 = uv_buf_init(&buf, sizeof(buf));
 if (resultFD == -1) {
 fprintf(stderr, "Error opening file: %s.\n",
 uv_strerror(resultFD));
 }


 uv_fs_req_cleanup(req);
 uv_fs_write(loop, &write_req, resultFD, &buf1, sizeof(buf1), -1, write_cb);
}


void write_cb(uv_fs_t* req) {
 int result = req->result;


 if (result == -1) {
 fprintf(stderr, "Error writting data to file: %s.\n",
 uv_strerror(result));
 }


 uv_fs_req_cleanup(req);
 uv_fs_close(loop, &close_req, open_req.result, close_cb);
}


void close_cb(uv_fs_t* req) {
 int result = req->result;


 if (result == -1) {
 fprintf(stderr, "Error closing file: %s.\n",
 uv_strerror(result));
 }


 uv_fs_req_cleanup(req);
  
}


int main(int argc, char** argv)
{
 int port = 8011;
 loop = uv_default_loop();
 if (server_start(port))
 {
   
 return 1;
 }
 int r = uv_fs_open(loop, &open_req, logfile, O_CREAT | O_APPEND, 0644, 
open_cb);


 if (r) {
 fprintf(stderr, "Error opening file: %s.\n",
 uv_strerror(r));
 }
  
 uv_run(loop, UV_RUN_DEFAULT);
 return 0;
}


This code is working and it creates the file and append the "Server 
Started!\n"
String . 
but the problem is when i try to write to the file from different place in 
the code for example :
where i try to print the http request buffer ig getting exception in > 
libuv_httpparser_ws.exe!uv__get_osfhandle(int 
fd) Line 174 C  
in file : handle-inl.h



void after_read(uv_stream_t* handle, ssize_t nread, const uv_buf_t * buf) {
 if (nread < 0) {
  
 if (buf->base) {
 free(buf->base);
 } 
 uv_close((uv_handle_t*)handle, on_close);
 return;
 }
 if (nread == 0) {
 free(buf->base);
 return;
 }
 
 _context* ctx = handle->data;
  
 if (ctx->request->handshake == 0) {
 //here you getting the request from the client 
  
 printf("buf->base %s\n", buf->base);
 uv_fs_write(loop, &write_req, resultFD, buf->base, sizeof(buf->base), -1, 
write_cb); //<---HERE I TRY TO WRITE TO THE FILE WITHOUT SUCCESS
 size_t np = http_parser_execute(ctx->parser, &settings, buf->base, nread);
  
 int _http_errno =ctx->parser->http_errno;
 const char * _errno = http_errno_description((enum http_errno)_http_errno);
 int _upgrade = ctx->parser->upgrade;
  
 free(buf->base);
 if (np != nread) {
 uv_shutdown_t* req;
 req = (uv_shutdown_t*)malloc(sizeof *req);
 uv_shutdown(req, handle, after_shutdown);
 }
 }
}

what am i doing wrong and how to make proper simple logger ?
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to