struct bfd_control_socket *control_new(int sd);
static void control_free(struct bfd_control_socket *bcs);
static void control_reset_buf(struct bfd_control_buffer *bcb);
-static int control_read(struct thread *t);
-static int control_write(struct thread *t);
+static void control_read(struct thread *t);
+static void control_write(struct thread *t);
static void control_handle_request_add(struct bfd_control_socket *bcs,
struct bfd_control_msg *bcm);
{
struct bfd_control_socket *bcs;
- if (bglobal.bg_csockev) {
- thread_cancel(bglobal.bg_csockev);
- bglobal.bg_csockev = NULL;
- }
+ thread_cancel(&bglobal.bg_csockev);
socket_close(&bglobal.bg_csock);
}
}
-int control_accept(struct thread *t)
+void control_accept(struct thread *t)
{
int csock, sd = THREAD_FD(t);
csock = accept(sd, NULL, 0);
if (csock == -1) {
zlog_warn("%s: accept: %s", __func__, strerror(errno));
- return 0;
+ return;
}
control_new(csock);
- bglobal.bg_csockev = NULL;
thread_add_read(master, control_accept, NULL, sd, &bglobal.bg_csockev);
-
- return 0;
}
struct bfd_control_queue *bcq;
struct bfd_notify_peer *bnp;
- if (bcs->bcs_ev) {
- thread_cancel(bcs->bcs_ev);
- bcs->bcs_ev = NULL;
- }
-
- if (bcs->bcs_outev) {
- thread_cancel(bcs->bcs_outev);
- bcs->bcs_outev = NULL;
- }
+ thread_cancel(&(bcs->bcs_ev));
+ thread_cancel(&(bcs->bcs_outev));
close(bcs->bcs_sd);
return 1;
empty_list:
- if (bcs->bcs_outev) {
- thread_cancel(bcs->bcs_outev);
- bcs->bcs_outev = NULL;
- }
+ thread_cancel(&(bcs->bcs_outev));
bcs->bcs_bout = NULL;
return 0;
}
bcb->bcb_left = 0;
}
-static int control_read(struct thread *t)
+static void control_read(struct thread *t)
{
struct bfd_control_socket *bcs = THREAD_ARG(t);
struct bfd_control_buffer *bcb = &bcs->bcs_bin;
bread = read(sd, &bcm, sizeof(bcm));
if (bread == 0) {
control_free(bcs);
- return 0;
+ return;
}
if (bread < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
zlog_warn("%s: read: %s", __func__, strerror(errno));
control_free(bcs);
- return 0;
+ return;
}
/* Validate header fields. */
zlog_debug("%s: client closed due small message length: %d",
__func__, bcm.bcm_length);
control_free(bcs);
- return 0;
+ return;
}
if (bcm.bcm_ver != BMV_VERSION_1) {
zlog_debug("%s: client closed due bad version: %d", __func__,
bcm.bcm_ver);
control_free(bcs);
- return 0;
+ return;
}
/* Prepare the buffer to load the message. */
zlog_warn("%s: not enough memory for message size: %zu",
__func__, bcb->bcb_left);
control_free(bcs);
- return 0;
+ return;
}
memcpy(bcb->bcb_buf, &bcm, sizeof(bcm));
bread = read(sd, &bcb->bcb_buf[bcb->bcb_pos], bcb->bcb_left);
if (bread == 0) {
control_free(bcs);
- return 0;
+ return;
}
if (bread < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
zlog_warn("%s: read: %s", __func__, strerror(errno));
control_free(bcs);
- return 0;
+ return;
}
bcb->bcb_pos += bread;
schedule_next_read:
bcs->bcs_ev = NULL;
thread_add_read(master, control_read, bcs, sd, &bcs->bcs_ev);
-
- return 0;
}
-static int control_write(struct thread *t)
+static void control_write(struct thread *t)
{
struct bfd_control_socket *bcs = THREAD_ARG(t);
struct bfd_control_buffer *bcb = bcs->bcs_bout;
bwrite = write(sd, &bcb->bcb_buf[bcb->bcb_pos], bcb->bcb_left);
if (bwrite == 0) {
control_free(bcs);
- return 0;
+ return;
}
if (bwrite < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
bcs->bcs_outev = NULL;
thread_add_write(master, control_write, bcs,
bcs->bcs_sd, &bcs->bcs_outev);
- return 0;
+ return;
}
zlog_warn("%s: write: %s", __func__, strerror(errno));
control_free(bcs);
- return 0;
+ return;
}
bcb->bcb_pos += bwrite;
bcs->bcs_outev = NULL;
thread_add_write(master, control_write, bcs, bcs->bcs_sd,
&bcs->bcs_outev);
- return 0;
+ return;
}
control_queue_dequeue(bcs);
-
- return 0;
}