int netserver_send(NETSERVER *s, NETCHUNK *chunk) { if(chunk->data_size >= NET_MAX_PAYLOAD) { dbg_msg("netserver", "packet payload too big. %d. dropping packet", chunk->data_size); return -1; } if(chunk->flags&NETSENDFLAG_CONNLESS) { /* send connectionless packet */ send_packet_connless(s->socket, &chunk->address, chunk->data, chunk->data_size); } else { int f = 0; dbg_assert(chunk->client_id >= 0, "errornous client id"); dbg_assert(chunk->client_id < s->max_clients, "errornous client id"); if(chunk->flags&NETSENDFLAG_VITAL) f = NET_CHUNKFLAG_VITAL; conn_queue_chunk(&s->slots[chunk->client_id].conn, f, chunk->data_size, chunk->data); if(chunk->flags&NETSENDFLAG_FLUSH) conn_flush(&s->slots[chunk->client_id].conn); } return 0; }
static void boxc_sender(void *arg) { Msg *msg; Boxc *conn = arg; gwlist_add_producer(flow_threads); while (bb_status != BB_DEAD && conn->alive) { /* * Make sure there's no data left in the outgoing connection before * doing the potentially blocking gwlist_consume()s */ conn_flush(conn->conn); gwlist_consume(suspended); /* block here if suspended */ if ((msg = gwlist_consume(conn->incoming)) == NULL) { /* tell sms/wapbox to die */ msg = msg_create(admin); msg->admin.command = restart ? cmd_restart : cmd_shutdown; send_msg(conn, msg); msg_destroy(msg); break; } if (msg_type(msg) == heartbeat) { debug("bb.boxc", 0, "boxc_sender: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } boxc_sent_push(conn, msg); if (!conn->alive || send_msg(conn, msg) == -1) { /* we got message here */ boxc_sent_pop(conn, msg, NULL); gwlist_produce(conn->retry, msg); break; } msg_destroy(msg); debug("bb.boxc", 0, "boxc_sender: sent message to <%s>", octstr_get_cstr(conn->client_ip)); } /* the client closes the connection, after that die in receiver */ /* conn->alive = 0; */ /* set conn to unroutable */ conn->routable = 0; gwlist_remove_producer(flow_threads); }