mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
session id always be positive
This commit is contained in:
47
gate/mread.c
47
gate/mread.c
@@ -107,7 +107,7 @@ client_send(struct send_client *c, int fd) {
|
|||||||
switch(errno) {
|
switch(errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
continue;
|
continue;
|
||||||
case EAGAIN:
|
case EWOULDBLOCK:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free_buffer(c);
|
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
|
void
|
||||||
mread_push(struct mread_pool *self, int id, void * buffer, int size, void * ptr) {
|
mread_push(struct mread_pool *self, int id, void * buffer, int size, void * ptr) {
|
||||||
struct socket * s = &self->sockets[id];
|
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) {
|
switch(errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
continue;
|
continue;
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// write error : close fd
|
||||||
|
s->status = SOCKET_HALFCLOSE;
|
||||||
|
try_close(self, s);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -327,25 +353,6 @@ _read_queue(struct mread_pool * self, int timeout) {
|
|||||||
return n;
|
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 *
|
inline static struct socket *
|
||||||
_read_one(struct mread_pool * self) {
|
_read_one(struct mread_pool * self) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ skynet_context_new(const char * name, const char *param) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
skynet_context_newsession(struct skynet_context *ctx) {
|
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;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,8 +354,6 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
|||||||
char * session_ptr = NULL;
|
char * session_ptr = NULL;
|
||||||
int ti = strtol(param, &session_ptr, 10);
|
int ti = strtol(param, &session_ptr, 10);
|
||||||
int session = skynet_context_newsession(context);
|
int session = skynet_context_newsession(context);
|
||||||
if (session < 0)
|
|
||||||
return NULL;
|
|
||||||
skynet_timeout(context->handle, ti, session);
|
skynet_timeout(context->handle, ti, session);
|
||||||
sprintf(context->result, "%d", session);
|
sprintf(context->result, "%d", session);
|
||||||
return context->result;
|
return context->result;
|
||||||
|
|||||||
Reference in New Issue
Block a user