提交 e95fc28b 编写于 作者: K Kozlov Dmitry

log-tcp: fixed incorrect queue overflow handling

ppp: fixed memory leak when ipcp raises error at ConfReq
上级 50881d86
......@@ -112,12 +112,12 @@ static void show_ses_help(char * const *fields, int fields_cnt, void *client)
static void ppp_terminate_soft(struct ppp_t *ppp)
{
ppp_terminate(ppp, 0, TERM_ADMIN_RESET);
ppp_terminate(ppp, TERM_ADMIN_RESET, 0);
}
static void ppp_terminate_hard(struct ppp_t *ppp)
{
ppp_terminate(ppp, 1, TERM_ADMIN_RESET);
ppp_terminate(ppp, TERM_ADMIN_RESET, 1);
}
static void terminate_help(char * const *fields, int fields_cnt, void *client);
......
......@@ -332,6 +332,7 @@ static void start_server(const char *host, int port)
addr.sin_addr.s_addr = inet_addr(host);
triton_context_register(&serv_ctx, NULL);
triton_context_set_priority(&serv_ctx, 1);
triton_md_register_handler(&serv_ctx, &serv_hnd);
triton_md_enable_handler(&serv_hnd, MD_MODE_READ);
triton_context_wakeup(&serv_ctx);
......
......@@ -621,6 +621,7 @@ static void start_server(const char *host, int port)
addr.sin_addr.s_addr = inet_addr(host);
triton_context_register(&serv_ctx, NULL);
triton_context_set_priority(&serv_ctx, 1);
triton_md_register_handler(&serv_ctx, &serv_hnd);
triton_md_enable_handler(&serv_hnd, MD_MODE_READ);
triton_context_wakeup(&serv_ctx);
......
......@@ -111,6 +111,7 @@ static void queue_log(struct tcp_target_t *t, struct log_msg_t *msg)
if (t->queue_len == conf_queue_len) {
spin_unlock(&t->lock);
log_free_msg(msg);
return;
}
list_add_tail(&msg->entry, &t->queue);
t->queue_len++;
......@@ -182,7 +183,8 @@ static int log_tcp_connect(struct triton_md_handler_t *h)
t->wait = 1;
spin_unlock(&t->lock);
send_log(t);
if (send_log(t))
triton_md_enable_handler(&t->hnd, MD_MODE_WRITE);
return 0;
}
......@@ -258,6 +260,8 @@ static int start_log(const char *_opt)
INIT_LIST_HEAD(&t->queue);
spinlock_init(&t->lock);
start_connect(t);
log_register_target(&t->target);
......
......@@ -210,6 +210,8 @@ static void destablish_ppp(struct ppp_t *ppp)
_free_layers(ppp);
ppp->terminated = 1;
log_ppp_debug("ppp destablished\n");
triton_event_fire(EV_PPP_FINISHED, ppp);
......@@ -411,7 +413,11 @@ void __export ppp_terminate(struct ppp_t *ppp, int cause, int hard)
struct ppp_layer_data_t *d;
int s = 0;
time(&ppp->stop_time);
if (ppp->terminated)
return;
if (!ppp->stop_time)
time(&ppp->stop_time);
if (!ppp->terminate_cause)
ppp->terminate_cause = cause;
......
......@@ -98,6 +98,7 @@ struct ppp_t
struct ppp_ctrl_t *ctrl;
int terminating:1;
int terminated:1;
int terminate_cause;
void *chan_buf;
......
......@@ -579,8 +579,10 @@ static void ipcp_recv(struct ppp_handler_t*h)
switch(hdr->code) {
case CONFREQ:
r = ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN);
if (ipcp->ppp->stop_time)
if (ipcp->ppp->stop_time) {
ipcp_free_conf_req(ipcp);
return;
}
switch(r) {
case IPCP_OPT_ACK:
ppp_fsm_recv_conf_req_ack(&ipcp->fsm);
......
......@@ -205,7 +205,10 @@ int triton_queue_ctx(struct _triton_context_t *ctx)
spin_lock(&threads_lock);
if (list_empty(&sleep_threads)) {
list_add_tail(&ctx->entry2, &ctx_queue);
if (ctx->priority)
list_add(&ctx->entry2, &ctx_queue);
else
list_add_tail(&ctx->entry2, &ctx_queue);
spin_unlock(&threads_lock);
ctx->queued = 1;
//printf("ctx %p: queued\n", ctx);
......@@ -318,6 +321,13 @@ void __export triton_context_unregister(struct triton_context_t *ud)
}
}
void __export triton_context_set_priority(struct triton_context_t *ud, int prio)
{
struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd;
ctx->priority = prio > 0;
}
void __export triton_context_schedule(struct triton_context_t *ud)
{
struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd;
......@@ -333,16 +343,10 @@ void __export triton_context_schedule(struct triton_context_t *ud)
ctx->thread = NULL;
spin_unlock(&ctx->lock);
while (1) {
if (swapcontext(&ctx->uctx, uctx)) {
if (errno == EINTR)
continue;
triton_log_error("swaswpntext: %s\n", strerror(errno));
} else
break;
}
__sync_fetch_and_add(&triton_stat.context_sleeping, 1);
if (swapcontext(&ctx->uctx, uctx))
triton_log_error("swaswpntext: %s\n", strerror(errno));
}
void triton_context_print(void)
......
......@@ -68,6 +68,7 @@ struct triton_stat_t
extern struct triton_stat_t triton_stat;
int triton_context_register(struct triton_context_t *, void *arg);
void triton_context_unregister(struct triton_context_t *);
void triton_context_set_priority(struct triton_context_t *, int);
void triton_context_schedule(struct triton_context_t *);
int triton_context_wakeup(struct triton_context_t *);
int triton_context_call(struct triton_context_t *, void (*func)(void *), void *arg);
......
......@@ -44,6 +44,7 @@ struct _triton_context_t
int need_close:1;
int need_free:1;
int pending:1;
int priority:1;
struct triton_context_t *ud;
void *bf_arg;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册