Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
haipome committed Jul 25, 2016
1 parent e023043 commit f8a4a41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 12 additions & 6 deletions asnw/nw_clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ nw_clt *nw_clt_create(nw_clt_cfg *cfg, nw_clt_type *type, void *privdata)
memset(clt, 0, sizeof(nw_clt));
clt->type = *type;
clt->reconnect_timeout = cfg->reconnect_timeout == 0 ? 1.0 : cfg->reconnect_timeout;
clt->buf_pool = nw_buf_pool_create(cfg->max_pkg_size);
if (cfg->buf_pool) {
clt->custom_buf_pool = true;
clt->buf_pool = cfg->buf_pool;
} else {
clt->custom_buf_pool = false;
clt->buf_pool = nw_buf_pool_create(cfg->max_pkg_size);
if (clt->buf_pool == NULL) {
nw_clt_release(clt);
return NULL;
}
}
clt->read_mem = cfg->read_mem;
clt->write_mem = cfg->write_mem;
if (clt->buf_pool == NULL) {
nw_clt_release(clt);
return NULL;
}

nw_addr_t *host_addr = malloc(sizeof(nw_addr_t));
if (host_addr == NULL) {
Expand Down Expand Up @@ -241,7 +247,7 @@ void nw_clt_release(nw_clt *clt)
if (clt->ses.write_buf) {
nw_ses_release(&clt->ses);
}
if (clt->buf_pool) {
if (!clt->custom_buf_pool && clt->buf_pool) {
nw_buf_pool_release(clt->buf_pool);
}
free(clt->ses.host_addr);
Expand Down
2 changes: 2 additions & 0 deletions asnw/nw_clt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef struct nw_clt_cfg {
uint32_t read_mem;
uint32_t write_mem;
double reconnect_timeout;
nw_buf_pool *buf_pool;
} nw_clt_cfg;

typedef struct nw_clt_type {
Expand All @@ -36,6 +37,7 @@ typedef struct nw_clt_type {
typedef struct nw_clt {
nw_ses ses;
nw_clt_type type;
bool custom_buf_pool;
nw_buf_pool *buf_pool;
nw_timer timer;
bool connected;
Expand Down
6 changes: 2 additions & 4 deletions asnw/nw_ses.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,13 @@ static void on_can_connect(nw_ses *ses)
{
if (ses->sockfd < 0)
return;

errno = nw_sock_errno(ses->sockfd);
if (errno != 0) {
ses->on_connect(ses, false);
return;
}

ses->on_connect(ses, true);
watch_read(ses);
ses->on_connect(ses, true);
}

static void libev_on_read_write_evt(struct ev_loop *loop, ev_io *watcher, int events)
Expand Down Expand Up @@ -378,8 +376,8 @@ int nw_ses_connect(nw_ses *ses, nw_addr_t *addr)
{
int ret = connect(ses->sockfd, NW_SOCKADDR(addr), addr->addrlen);
if (ret == 0) {
ses->on_connect(ses, true);
watch_read(ses);
ses->on_connect(ses, true);
return 0;
}
if (errno == EINPROGRESS) {
Expand Down

0 comments on commit f8a4a41

Please sign in to comment.