enable read

This commit is contained in:
Cloud Wu
2020-10-12 22:34:46 +08:00
parent f3acbe46df
commit a4221deac1

View File

@@ -524,34 +524,6 @@ check_wb_list(struct wb_list *s) {
assert(s->tail == NULL);
}
static struct socket *
new_fd(struct socket_server *ss, int id, int fd, int protocol, uintptr_t opaque, bool reading) {
struct socket * s = &ss->slot[HASH_ID(id)];
assert(s->type == SOCKET_TYPE_RESERVE);
if (sp_add(ss->event_fd, fd, s)) {
s->type = SOCKET_TYPE_INVALID;
return NULL;
}
s->id = id;
s->fd = fd;
s->reading = reading;
s->writing = false;
s->sending = ID_TAG16(id) << 16 | 0;
s->protocol = protocol;
s->p.size = MIN_READ_BUFFER;
s->opaque = opaque;
s->wb_size = 0;
s->warn_size = 0;
check_wb_list(&s->high);
check_wb_list(&s->low);
s->dw_buffer = NULL;
s->dw_size = 0;
memset(&s->stat, 0, sizeof(s->stat));
return s;
}
static inline void
enable_write(struct socket_server *ss, struct socket *s, bool enable) {
if (s->writing != enable) {
@@ -568,6 +540,35 @@ enable_read(struct socket_server *ss, struct socket *s, bool enable) {
}
}
static struct socket *
new_fd(struct socket_server *ss, int id, int fd, int protocol, uintptr_t opaque, bool reading) {
struct socket * s = &ss->slot[HASH_ID(id)];
assert(s->type == SOCKET_TYPE_RESERVE);
if (sp_add(ss->event_fd, fd, s)) {
s->type = SOCKET_TYPE_INVALID;
return NULL;
}
s->id = id;
s->fd = fd;
s->reading = true;
s->writing = false;
s->sending = ID_TAG16(id) << 16 | 0;
s->protocol = protocol;
s->p.size = MIN_READ_BUFFER;
s->opaque = opaque;
s->wb_size = 0;
s->warn_size = 0;
check_wb_list(&s->high);
check_wb_list(&s->low);
s->dw_buffer = NULL;
s->dw_size = 0;
memset(&s->stat, 0, sizeof(s->stat));
enable_read(ss, s, reading);
return s;
}
static inline void
stat_read(struct socket_server *ss, struct socket *s, int n) {
s->stat.read += n;