session id always be positive

This commit is contained in:
云风
2013-08-02 10:45:00 +08:00
parent 1d0d2678ed
commit 6be6a8171f
2 changed files with 29 additions and 23 deletions

View File

@@ -107,7 +107,7 @@ client_send(struct send_client *c, int fd) {
switch(errno) {
case EINTR:
continue;
case EAGAIN:
case EWOULDBLOCK:
return;
}
free_buffer(c);
@@ -143,6 +143,25 @@ client_push(struct send_client *c, void * buf, int sz, void * ptr) {
}
}
static void
try_close(struct mread_pool * self, struct socket * s) {
if (s->client.head == NULL) {
turn_off(self, s);
}
if (s->status != SOCKET_HALFCLOSE) {
return;
}
if (s->client.head == NULL) {
s->status = SOCKET_CLOSED;
s->node = NULL;
s->temp = NULL;
event_del(self->efd, s->fd);
close(s->fd);
// printf("MREAD close %d (fd=%d)\n",id,s->fd);
++self->closed;
}
}
void
mread_push(struct mread_pool *self, int id, void * buffer, int size, void * ptr) {
struct socket * s = &self->sockets[id];
@@ -160,6 +179,13 @@ mread_push(struct mread_pool *self, int id, void * buffer, int size, void * ptr)
switch(errno) {
case EINTR:
continue;
case EWOULDBLOCK:
break;
default:
// write error : close fd
s->status = SOCKET_HALFCLOSE;
try_close(self, s);
return;
}
break;
}
@@ -327,25 +353,6 @@ _read_queue(struct mread_pool * self, int timeout) {
return n;
}
static void
try_close(struct mread_pool * self, struct socket * s) {
if (s->client.head == NULL) {
turn_off(self, s);
}
if (s->status != SOCKET_HALFCLOSE) {
return;
}
if (s->client.head == NULL) {
s->status = SOCKET_CLOSED;
s->node = NULL;
s->temp = NULL;
event_del(self->efd, s->fd);
close(s->fd);
// printf("MREAD close %d (fd=%d)\n",id,s->fd);
++self->closed;
}
}
inline static struct socket *
_read_one(struct mread_pool * self) {
for (;;) {

View File

@@ -127,7 +127,8 @@ skynet_context_new(const char * name, const char *param) {
int
skynet_context_newsession(struct skynet_context *ctx) {
int session = ++ctx->session_id;
// session always be a positive number
int session = (++ctx->session_id) & 0x7fffffff;
return session;
}
@@ -353,8 +354,6 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
char * session_ptr = NULL;
int ti = strtol(param, &session_ptr, 10);
int session = skynet_context_newsession(context);
if (session < 0)
return NULL;
skynet_timeout(context->handle, ti, session);
sprintf(context->result, "%d", session);
return context->result;