Skip to content

Commit

Permalink
use trylock in send_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Jun 21, 2017
1 parent 171f8ee commit aa42534
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions skynet-src/socket_server.c
Expand Up @@ -682,7 +682,8 @@ send_buffer_(struct socket_server *ss, struct socket *s, struct socket_message *

static int
send_buffer(struct socket_server *ss, struct socket *s, struct socket_message *result) {
spinlock_lock(&s->dw_lock);
if (!spinlock_trylock(&s->dw_lock))
return -1; // blocked by direct write, send later.
if (s->dw_buffer) {
// add direct write buffer before high.head
struct write_buffer * buf = MALLOC(SIZEOF_TCPBUFFER);
Expand Down Expand Up @@ -1445,8 +1446,9 @@ socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz
s->dw_buffer = buffer;
s->dw_size = sz;
s->dw_offset = n;
sp_write(ss->event_fd, s->fd, s, true);
spinlock_unlock(&s->dw_lock);

sp_write(ss->event_fd, s->fd, s, true);
return 0;
}
spinlock_unlock(&s->dw_lock);
Expand Down

0 comments on commit aa42534

Please sign in to comment.