Browse Source

Various fixes to make the web server not give off so many errors.

v0.7.4-release
Ryan 16 years ago
parent
commit
ae7c6314ca
  1. 35
      deps/liboi/oi_socket.c
  2. 3
      src/net.cc
  3. 4
      src/net.h

35
deps/liboi/oi_socket.c

@ -108,8 +108,14 @@ static int
full_close(oi_socket *socket) full_close(oi_socket *socket)
{ {
//printf("close(%d)\n", socket->fd); //printf("close(%d)\n", socket->fd);
if (close(socket->fd) == -1) if (close(socket->fd) == -1) {
return errno == EINTR ? AGAIN : ERROR; if (errno == EINTR)
return AGAIN;
else {
socket->errorno = errno;
return ERROR;
}
}
socket->read_action = NULL; socket->read_action = NULL;
socket->write_action = NULL; socket->write_action = NULL;
@ -135,6 +141,8 @@ half_close(oi_socket *socket)
} }
} }
socket->write_action = NULL; socket->write_action = NULL;
if (socket->read_action == NULL)
socket->fd = -1;
return OKAY; return OKAY;
} }
@ -497,7 +505,7 @@ socket_recv (oi_socket *socket)
if (!socket->connected) { if (!socket->connected) {
socket->connected = TRUE; socket->connected = TRUE;
if (socket->on_connect) socket->on_connect(socket); if (socket->on_connect) socket->on_connect(socket);
return OKAY; //return OKAY;
} }
recved = recv(socket->fd, buf, buf_size, 0); recved = recv(socket->fd, buf, buf_size, 0);
@ -520,9 +528,14 @@ socket_recv (oi_socket *socket)
socket->errorno = errno; socket->errorno = errno;
return ERROR; return ERROR;
case ECONNRESET:
socket->errorno = errno;
return ERROR;
default: default:
socket->errorno = errno;
perror("recv()"); perror("recv()");
printf("unmatched errno %d %s\n\n", errno, strerror(errno)); printf("unmatched errno %d %s\n\n", socket->errorno, strerror(errno));
assert(0 && "recv returned error that oi should have caught before."); assert(0 && "recv returned error that oi should have caught before.");
return ERROR; return ERROR;
} }
@ -800,6 +813,7 @@ on_io_event(EV_P_ ev_io *watcher, int revents)
ev_clear_pending (EV_A_ &socket->timeout_watcher); ev_clear_pending (EV_A_ &socket->timeout_watcher);
oi_socket_detach(socket); oi_socket_detach(socket);
assert(socket->fd == -1);
if (socket->on_close) { socket->on_close(socket); } if (socket->on_close) { socket->on_close(socket); }
/* WARNING: user can free socket in on_close so no more /* WARNING: user can free socket in on_close so no more
@ -877,14 +891,17 @@ void oi_socket_force_close (oi_socket *socket)
{ {
release_write_buffer(socket); release_write_buffer(socket);
ev_clear_pending (EV_A_ &socket->write_watcher); ev_clear_pending (SOCKET_LOOP_ &socket->write_watcher);
ev_clear_pending (EV_A_ &socket->read_watcher); ev_clear_pending (SOCKET_LOOP_ &socket->read_watcher);
ev_clear_pending (EV_A_ &socket->timeout_watcher); ev_clear_pending (SOCKET_LOOP_ &socket->timeout_watcher);
socket->write_action = socket->read_action = NULL; socket->write_action = socket->read_action = NULL;
// socket->errorno = OI_SOCKET_ERROR_FORCE_CLOSE // socket->errorno = OI_SOCKET_ERROR_FORCE_CLOSE
close(socket->fd); //
if (socket->fd > 0) {
close(socket->fd);
}
socket->fd = -1; socket->fd = -1;
oi_socket_detach(socket); oi_socket_detach(socket);

3
src/net.cc

@ -21,9 +21,6 @@ using namespace node;
#define ON_ERROR_SYMBOL String::NewSymbol("onError") #define ON_ERROR_SYMBOL String::NewSymbol("onError")
#define ON_EOF_SYMBOL String::NewSymbol("onEOF") #define ON_EOF_SYMBOL String::NewSymbol("onEOF")
#define SEND_SYMBOL String::NewSymbol("send")
#define DISCONNECT_SYMBOL String::NewSymbol("disconnect")
#define CONNECT_SYMBOL String::NewSymbol("connect")
#define ENCODING_SYMBOL String::NewSymbol("encoding") #define ENCODING_SYMBOL String::NewSymbol("encoding")
#define TIMEOUT_SYMBOL String::NewSymbol("timeout") #define TIMEOUT_SYMBOL String::NewSymbol("timeout")
#define SERVER_SYMBOL String::NewSymbol("server") #define SERVER_SYMBOL String::NewSymbol("server")

4
src/net.h

@ -69,6 +69,10 @@ private:
static void on_close (oi_socket *s) { static void on_close (oi_socket *s) {
Connection *connection = static_cast<Connection*> (s->data); Connection *connection = static_cast<Connection*> (s->data);
connection->OnDisconnect(); connection->OnDisconnect();
if (s->errorno)
printf("socket died with error %d\n", s->errorno);
connection->Detach(); connection->Detach();
} }

Loading…
Cancel
Save