static Msg *sms_receive(SMSCConn *conn) { SmscWrapper *wrap = conn->data; int ret; Msg *newmsg = NULL; if (smscenter_pending_smsmessage(wrap->smsc) == 1) { ret = smscenter_receive_msg(wrap->smsc, &newmsg); if (ret == 1) { /* if any smsc_id available, use it */ newmsg->sms.smsc_id = octstr_duplicate(conn->id); return newmsg; } else if (ret == 0) { /* "NEVER" happens */ warning(0, "SMSC %s: Pending message returned '1', " "but nothing to receive!", octstr_get_cstr(conn->name)); msg_destroy(newmsg); return NULL; } else { msg_destroy(newmsg); if (reconnect(conn) == -1) smscconn_shutdown(conn, 0); return NULL; } } return NULL; }
static void udp_sender(void *arg) { Msg *msg; Udpc *conn = arg; gwlist_add_producer(flow_threads); while (1) { if ((msg = gwlist_consume(conn->outgoing_list)) == NULL) break; info(0, "sending datagram <%s:%ld> -> <%s:%ld>", octstr_get_cstr(msg->wdp_datagram.source_address), msg->wdp_datagram.source_port, octstr_get_cstr(msg->wdp_datagram.destination_address), msg->wdp_datagram.destination_port); dump(msg); if (send_udp(conn->fd, msg) == -1) { msg_destroy(msg); continue; } counter_increase(outgoing_wdp_counter); msg_destroy(msg); } gwthread_join(conn->receiver); udpc_destroy(conn); gwlist_remove_producer(flow_threads); }
static void udp_sender(void *arg) { Msg *msg; Udpc *conn = arg; gwlist_add_producer(flow_threads); while(bb_status != BB_DEAD) { gwlist_consume(suspended); /* block here if suspended */ if ((msg = gwlist_consume(conn->outgoing_list)) == NULL) break; debug("bb.udp", 0, "udp: sending message"); if (send_udp(conn->fd, msg) == -1) /* ok, we failed... tough * XXX log the message or something like that... but this * is not as fatal as it is with SMS-messages... */ { msg_destroy(msg); continue; } counter_increase(outgoing_wdp_counter); msg_destroy(msg); } gwthread_join(conn->receiver); udpc_destroy(conn); gwlist_remove_producer(flow_threads); }
/**Reply to an incoming transaction request (stdarg version). * * @deprecated * Use nta_incoming_treply() instead. */ int nta_incoming_vreply(nta_incoming_t *irq, int status, char const *phrase, void const *extra, va_list headers) { if (irq->irq_status < 200 || status < 200 || (irq->irq_method == sip_method_invite && status < 300)) { msg_t *msg = nta_msg_create(irq->irq_agent, 0); sip_t *sip = sip_object(msg); if (!msg) return -1; else if (nta_msg_response_complete(msg, irq, status, phrase) < 0) msg_destroy(msg); else if (sip_add_headers(msg, sip, extra, headers) < 0 ) msg_destroy(msg); else if (sip_message_complete(msg) < 0) msg_destroy(msg); else if (nta_incoming_mreply(irq, msg) < 0) msg_destroy(msg); else return 0; } return -1; }
static void he_recv_message(nth_engine_t * he, tport_t * tport, msg_t *msg, void *arg, su_time_t now) { nth_client_t *hc, **hcp; tp_name_t const *tpn; for (hcp = hc_htable_hash(he->he_clients, (hash_value_t)(uintptr_t) tport); (hc = *hcp); hcp = hc_htable_next(he->he_clients, hcp)) { if (hc->hc_tport == tport) { if (hc_recv(hc, msg, http_object(msg)) < 0) msg_destroy(msg); return; } } /* Extra response? Framing error? */ tpn = tport_name(tport); if (msg_size(msg)) SU_DEBUG_3(("nth client: received extra data ("MOD_ZU" bytes) " "from %s/%s:%s\n", (size_t)msg_size(msg), tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port)); else SU_DEBUG_3(("nth client: received extra data from %s/%s:%s\n", tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port)); msg_destroy(msg); tport_shutdown(tport, 2); }
static void smsbox_thread(void *arg) { Connection *conn; Msg *msg; Octstr *os; Octstr *reply_msg; unsigned long count; msg = msg_create(sms); msg->sms.sender = octstr_create("123"); msg->sms.receiver = octstr_create("456"); msg->sms.msgdata = octstr_create("hello world"); reply_msg = msg_pack(msg); msg_destroy(msg); gwthread_sleep(1.0); conn = conn_open_tcp(bearerbox_host, port_for_smsbox, NULL); if (conn == NULL) { gwthread_sleep(2.0); conn = conn_open_tcp(bearerbox_host, port_for_smsbox, NULL); if (conn == NULL) panic(0, "Couldn't connect to bearerbox as smsbox"); } while (!quitting && conn_wait(conn, -1.0) != -1) { for (;;) { os = conn_read_withlen(conn); if (os == NULL) { if (conn_eof(conn) || conn_error(conn)) goto error; break; } msg = msg_unpack(os); if (msg == NULL || msg->type == wdp_datagram) error(0, "Bearerbox sent garbage to smsbox"); if (msg->type == sms) { if (first_from_bb == (time_t) -1) time(&first_from_bb); count = counter_increase(num_from_bearerbox) + 1; debug("test.smpp", 0, "Bearerbox sent sms #%ld <%s> to smsbox, sending reply.", count, octstr_get_cstr(msg->sms.msgdata)); if (count == max_to_esme) info(0, "Bearerbox has sent all messages to smsbox."); conn_write_withlen(conn, reply_msg); counter_increase(num_to_bearerbox); } msg_destroy(msg); octstr_destroy(os); time(&last_to_bb); } } error: conn_destroy(conn); octstr_destroy(reply_msg); debug("test.smpp", 0, "%s terminates.", __func__); }
/* * Read an Msg from the bearerbox and send it to the proper receiver * via a List. At the moment all messages are sent to the smsbox_requests * List. */ static void read_messages_from_bearerbox(void *arg) { time_t start, t; unsigned long secs; unsigned long total_s, total_f, total_ft, total_b, total_o; Msg *msg; total_s = total_f = total_ft = total_b = total_o = 0; start = t = time(NULL); while (program_status != shutting_down) { int ret; /* block infinite for reading messages */ ret = read_from_bearerbox(&msg, 0.5); if (ret == -1) break; else if (ret == 1) /* timeout */ continue; else if (msg == NULL) /* just to be sure, may not happens */ break; if (msg_type(msg) == admin) { if (msg->admin.command == cmd_shutdown || msg->admin.command == cmd_restart) { info(0, "Bearerbox told us to die"); program_status = shutting_down; } /* * XXXX here should be suspend/resume, add RSN */ msg_destroy(msg); } else if (msg_type(msg) == ack) { counter_increase(counter); switch (msg->ack.nack) { case ack_success: total_s++; break; case ack_failed: total_f++; break; case ack_failed_tmp: total_ft++; break; case ack_buffered: total_b++; break; } msg_destroy(msg); } else { warning(0, "Received other message than ack/admin, ignoring!"); msg_destroy(msg); total_o++; } } secs = difftime(time(NULL), start); info(0, "Received acks: %ld success, %ld failed, %ld failed temporarly, %ld queued, %ld other in %ld seconds " "(%.2f per second)", total_s, total_f, total_ft, total_b, total_o, secs, (float)(total_s+total_f+total_ft+total_b) / secs); }
static void bearerbox_to_sql(void *arg) { Boxc *conn = (Boxc *)arg; Msg *msg, *mack; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* garbage/connection lost */ /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: connection to bearerbox died."); break; } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_sql: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } /* if this is an identification message from an smsbox instance */ if (msg_type(msg) == admin && msg->admin.command == cmd_shutdown) { /* tell sqlbox to die */ conn->alive = 0; sqlbox_status = SQL_SHUTDOWN; debug("sqlbox", 0, "bearerbox_to_sql: Bearerbox told us to shutdown."); break; } if (msg_type(msg) == sms) { if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg, octstr_imm("DLR")); } } /* create ack message */ mack = msg_create(ack); mack->ack.nack = ack_success; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); send_msg(conn->bearerbox_connection, conn, mack); msg_destroy(mack); } msg_destroy(msg); } }
static void bearerbox_to_smsbox(void *arg) { Msg *msg, *msg_escaped; Boxc *conn = arg; while (sqlbox_status == SQL_RUNNING && conn->alive) { msg = read_from_box(conn->bearerbox_connection, conn); if (msg == NULL) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: connection to bearerbox died."); break; } if (msg_type(msg) == admin) { if (msg->admin.command == cmd_shutdown || msg->admin.command == cmd_restart) { /* tell sqlbox to die */ conn->alive = 0; debug("sqlbox", 0, "bearerbox_to_smsbox: Bearerbox told us to shutdown."); break; } } if (msg_type(msg) == heartbeat) { // todo debug("sqlbox", 0, "bearerbox_to_smsbox: catch an heartbeat - we are alive"); msg_destroy(msg); continue; } if (!conn->alive) { msg_destroy(msg); break; } if (msg_type(msg) == sms) { msg_escaped = msg_duplicate(msg); if (msg->sms.sms_type != report_mo) { if (save_mo) { gw_sql_save_msg(msg_escaped, octstr_imm("MO")); } } else { if (save_dlr) { gw_sql_save_msg(msg_escaped, octstr_imm("DLR")); } } msg_destroy(msg_escaped); } send_msg(conn->smsbox_connection, conn, msg); msg_destroy(msg); } /* the client closes the connection, after that die in receiver */ conn->alive = 0; }
static void smsbox_to_bearerbox(void *arg) { Boxc *conn = arg; Msg *msg, *msg_escaped; /* remove messages from socket until it is closed */ while (sqlbox_status == SQL_RUNNING && conn->alive) { //list_consume(suspended); /* block here if suspended */ msg = read_from_box(conn->smsbox_connection, conn); if (msg == NULL) { /* garbage/connection lost */ conn->alive = 0; break; } if (msg_type(msg) == sms) { debug("sqlbox", 0, "smsbox_to_bearerbox: sms received"); if (save_mt) { msg_escaped = msg_duplicate(msg); /* convert validity & deferred to minutes */ if (msg_escaped->sms.validity != SMS_PARAM_UNDEFINED) msg_escaped->sms.validity = (msg_escaped->sms.validity - time(NULL))/60; if (msg_escaped->sms.deferred != SMS_PARAM_UNDEFINED) msg_escaped->sms.deferred = (msg_escaped->sms.deferred - time(NULL))/60; gw_sql_save_msg(msg_escaped, octstr_imm("MT")); msg_destroy(msg_escaped); } } send_msg(conn->bearerbox_connection, conn, msg); /* if this is an identification message from an smsbox instance */ if (msg_type(msg) == admin && msg->admin.command == cmd_identify) { /* * any smsbox sends this command even if boxc_id is NULL, * but we will only consider real identified boxes */ if (msg->admin.boxc_id != NULL) { /* and add the boxc_id into conn for boxc_status() output */ conn->boxc_id = msg->admin.boxc_id; msg->admin.boxc_id = NULL; debug("sqlbox", 0, "smsbox_to_bearerbox: got boxc_id <%s> from <%s>", octstr_get_cstr(conn->boxc_id), octstr_get_cstr(conn->client_ip)); } } msg_destroy(msg); } conn->alive = 0; }
static void empty_msg_lists(void) { Msg *msg; #ifndef NO_WAP if (gwlist_len(incoming_wdp) > 0 || gwlist_len(outgoing_wdp) > 0) warning(0, "Remaining WDP: %ld incoming, %ld outgoing", gwlist_len(incoming_wdp), gwlist_len(outgoing_wdp)); info(0, "Total WDP messages: received %ld, sent %ld", counter_value(incoming_wdp_counter), counter_value(outgoing_wdp_counter)); #endif while ((msg = gwlist_extract_first(incoming_wdp)) != NULL) msg_destroy(msg); while ((msg = gwlist_extract_first(outgoing_wdp)) != NULL) msg_destroy(msg); gwlist_destroy(incoming_wdp, NULL); gwlist_destroy(outgoing_wdp, NULL); counter_destroy(incoming_wdp_counter); counter_destroy(outgoing_wdp_counter); #ifndef NO_SMS /* XXX we should record these so that they are not forever lost... */ if (gwlist_len(incoming_sms) > 0 || gwlist_len(outgoing_sms) > 0) debug("bb", 0, "Remaining SMS: %ld incoming, %ld outgoing", gwlist_len(incoming_sms), gwlist_len(outgoing_sms)); info(0, "Total SMS messages: received %ld, dlr %ld, sent %ld, dlr %ld", counter_value(incoming_sms_counter), counter_value(incoming_dlr_counter), counter_value(outgoing_sms_counter), counter_value(outgoing_dlr_counter)); #endif gwlist_destroy(incoming_sms, msg_destroy_item); gwlist_destroy(outgoing_sms, msg_destroy_item); counter_destroy(incoming_sms_counter); counter_destroy(incoming_dlr_counter); counter_destroy(outgoing_sms_counter); counter_destroy(outgoing_dlr_counter); load_destroy(incoming_sms_load); load_destroy(incoming_dlr_load); load_destroy(outgoing_sms_load); load_destroy(outgoing_dlr_load); }
int task_run(task_id tid, lua_State *L, message_t *m) { task_t *t = task_ref(tid); if (!t) return ERR_INVAL; task_set_current(tid); int rc = 0; int count; switch (t->status) { case ready: if (!m) { t->status = finished; break; } t->L = lua_newthread(L); count = lua_decodemessage(t->L, m) - 1; msg_destroy(m); t->status = running; STACK(t->L,"Resume from ready %f\n",t->id); rc = lua_resume(t->L, count); break; case suspended: count = m ? lua_decodemessage(t->L, m) : 0; if (m) msg_destroy(m); t->status = running; STACK(t->L,"Resume from suspended %f\n",t->id); rc = lua_resume(t->L, count); break; default: break; } if (rc == LUA_ERRRUN) { INFO("Error code %d",rc); t->status = error; STACK(t->L,"Error running task"); } else if (rc == LUA_YIELD) { STACK(t->L,"YIELDED (ref = %d)",t->ref_count); t->status = suspended; // TODO YIELD } else if (rc == 0) { STACK(t->L,"QUITTED (ref = %d)",t->ref_count); t->status = finished; } // TODO task->coro = get current coroutine task_set_current(0); task_free(tid); // TODO handle rc return SUCCESS; }
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); }
int main() { //printf("this is msg_ser!\n"); int msg_id = msg_create();//ser if(msg_id < 0) return 1; printf("ID:> %d\t\n\n",msg_id); char buf[G_SIZE]; while(1) { buf[G_SIZE-1]='\0'; int ret =msg_recv(msg_id,buf,\ sizeof(buf)-1,DATA_TYPE_CLI); printf("cli:>%s\n",buf); fflush(stdout); memset(buf,'\0',sizeof(buf)); printf("Please Input:\n "); char *ar = fgets(buf,sizeof(buf)-1,stdin); if(strncasecmp(ar,"quit",4) == 0) break; ret = msg_send(msg_id,buf,DATA_TYPE_SER); } msg_destroy(msg_id); // sleep(10); // int ret = msg_destroy(msg_id); // printf("destroy code is:> %d\n",ret); return 0; }
/* * Remove msg from sent queue. * Return 0 if message should be deleted from store and 1 if not (e.g. tmp nack) */ static void boxc_sent_pop(Boxc *conn, Msg *m, Msg **orig) { Octstr *os; char id[UUID_STR_LEN + 1]; Msg *msg; if (conn->is_wap || !conn->sent || !m || (msg_type(m) != ack && msg_type(m) != sms)) return; if (orig != NULL) *orig = NULL; uuid_unparse((msg_type(m) == sms ? m->sms.id : m->ack.id), id); os = octstr_create(id); msg = dict_remove(conn->sent, os); octstr_destroy(os); if (!msg) { error(0, "BOXC: Got ack for nonexistend message!"); msg_dump(m, 0); return; } semaphore_up(conn->pending); if (orig == NULL) msg_destroy(msg); else *orig = msg; }
int main() { int msg_id = msg_create(); //ser if(msg_id < 0) { return 1; } char buf[G_SIZE]; while(1) { buf[G_SIZE - 1] = '\0'; int ret = msg_recv(msg_id, buf, sizeof(buf)-1, DATA_TYPE_CLI); if(strncasecmp("quite", buf, 4) == 0) { break;} printf("cli:> %s\n", buf); printf("plase Enter:"); fflush(stdout); memset(buf, '\0', sizeof(buf)); fgets(buf, sizeof(buf)-1, stdin); ret = msg_send(msg_id, buf, DATA_TYPE_SER); } int ret = msg_destroy(msg_id); return 0; }
void log_vformat(gint priority, const gchar *msg, MessageTag *tag0, va_list vl) { Message *self; MessageTag *tag; if (g_log_diverted.m_divert_handler) { self = msg_vcreate(priority, msg, tag0, vl); g_log_diverted.m_divert_handler(self, g_log_diverted.m_user_data); msg_destroy(self); return; } if (!g_log_list || priority > g_log_max_priority) { tag = tag0; while (tag) { g_free(tag->m_tag); g_free(tag->m_value); g_free(tag); tag = va_arg(vl, MessageTag *); } return; }
static void dispatch_into_queue(Msg *msg) { char id[UUID_STR_LEN + 1]; gw_assert(msg != NULL), gw_assert(msg_type(msg) == sms); switch (msg->sms.sms_type) { case mt_push: case mt_reply: case report_mt: gwlist_append(outgoing_sms, msg); break; case mo: case report_mo: gwlist_append(incoming_sms, msg); break; default: uuid_unparse(msg->sms.id, id); error(0, "Not handled sms_type %ld within store for message ID %s", msg->sms.sms_type, id); msg_destroy(msg); break; } }
static int verified_file(const char *filename, const struct stat *sb, int tflag, struct FTW *ftwbuf) { Octstr *os; Msg *msg; /* we need to check here if we have a regular file. */ if (tflag != FTW_F) return 0; #else static int verified_file(const char *filename, const struct stat *sb, int tflag, void *ftwbuf) { Octstr *os; Msg *msg; #endif if ((os = octstr_read_file(filename)) == NULL) { return -1; } if ((msg = store_msg_unpack(os)) == NULL) { error(0, "Could not unpack DLR message `%s'", filename); octstr_destroy(os); return -1; } /* we could load and unpack, so this is verified */ counter_increase(counter); octstr_destroy(os); msg_destroy(msg); return 0; }
/**Forward a request. * * @deprecated * Use nta_outgoing_mcreate() instead. */ nta_outgoing_t *nta_outgoing_tclone(nta_agent_t *agent, nta_response_f *callback, nta_outgoing_magic_t *magic, url_string_t const *route_url, msg_t *parent, tag_type_t tag, tag_value_t value, ...) { ta_list ta; msg_t *msg; nta_outgoing_t *orq = NULL; if (parent == NULL) return NULL; if ((msg = nta_msg_create(agent, 0)) == NULL) return NULL; ta_start(ta, tag, value); msg_clone(msg, parent); if (parent && sip_copy_all(msg, sip_object(msg), sip_object(parent)) < 0) ; else if (sip_add_tl(msg, sip_object(msg), ta_tags(ta)) < 0) ; else orq = nta_outgoing_mcreate(agent, callback, magic, route_url, msg); ta_end(ta); if (!orq) msg_destroy(msg); return orq; }
static void tport_http_deliver(tport_t *self, msg_t *msg, su_time_t now) { tport_http_connect_instance_t *thci = (tport_http_connect_instance_t*)self; if (msg && thci->thci_response == msg) { tport_http_connect_t *thc = (tport_http_connect_t *)self->tp_pri; http_t *http = http_object(msg); if (http && http->http_status) { SU_DEBUG_0(("tport_http_connect: %u %s\n", http->http_status->st_status, http->http_status->st_phrase)); if (http->http_status->st_status < 300) { msg_buf_move(thci->thci_stackmsg, msg); thci->thci_response = NULL; thci->thci_stackmsg = NULL; return; } } msg_destroy(msg); thci->thci_response = NULL; tport_error_report(self, EPROTO, (void *)thc->thc_proxy->ai_addr); tport_close(self); return; } tport_base_deliver(self, msg, now); }
static int store_file_save_ack(Msg *msg, ack_status_t status) { Msg *mack; int ret; /* only sms are handled */ if (!msg || msg_type(msg) != sms) return -1; if (filename == NULL) return 0; mack = msg_create(ack); if (!mack) return -1; mack->ack.time = msg->sms.time; uuid_copy(mack->ack.id, msg->sms.id); mack->ack.nack = status; ret = store_save(mack); msg_destroy(mack); return ret; }
/**Create a request belonging to the leg * (stdarg version of nta_outgoing_create()). * * @deprecated * Use nta_outgoing_tcreate() or nta_outgoing_mcreate() instead. */ nta_outgoing_t *nta_outgoing_vcreate(nta_leg_t *leg, nta_response_f *callback, nta_outgoing_magic_t *magic, url_string_t const *route_url, sip_method_t method, char const *name, url_string_t const *request_uri, void const *extra, va_list headers) { nta_agent_t *agent = leg->leg_agent; msg_t *msg = nta_msg_create(agent, 0); sip_t *sip = sip_object(msg); nta_outgoing_t *orq; if (extra && sip_add_headers(msg, sip, extra, headers) < 0) orq = NULL; else if (route_url && leg->leg_route && !sip->sip_route && sip_add_dup(msg, sip, (sip_header_t *)leg->leg_route) < 0) orq = NULL; else if (nta_msg_request_complete(msg, leg, method, name, request_uri) < 0) orq = NULL; else orq = nta_outgoing_mcreate(agent, callback, magic, route_url, msg); if (!orq) msg_destroy(msg); return orq; }
void* accepter_thread(void* args){ printf("\n%s", "===================ACCEPTER THREAD START=================="); printf("\n%s", "lancio il thread accepter(in accepter)"); queue_and_list_t* p = (queue_and_list_t*)args; pthread_t get_message_queue_thread; msg_t* message_read; reader_t* new_reader; while(1){ pthread_create(&get_message_queue_thread, NULL, accepter_get_bloccante,(void*)p->requests_queue); pthread_join(get_message_queue_thread,(void*)&message_read); if(message_read->content) printf("\n%s : messaggio letto dall buffer delle richieste(in accepter)", (char*)message_read->content); if(message_read == POISON_PILL){ printf("\n%s", "ricevuta la poison pill(in accepter) TERMINO"); pthread_exit(2); } else{ new_reader = init_reader(message_read->content, SIZE_BUFFER_READER); pthread_mutex_lock(&(p->lista_reader_contes->blocco_list_mutex)); printf("\n%s : aggiungo il reader alla lista (in accepter)\n", new_reader->name); addElement(p->lista_reader_contes->reader_list, (void*)new_reader); pthread_mutex_unlock(&(p->lista_reader_contes->blocco_list_mutex)); parametri_reader* parametri = (parametri_reader*)malloc(sizeof(parametri_reader)); parametri->reader = new_reader; parametri->lista_reader_struct = p->lista_reader_contes; pthread_create(new_reader->tid_reader, NULL, reader_thread,(void*)parametri); msg_destroy(message_read); } } }
void msg_send_done( msg_t msg, status_t status ) { // char str[64]; // sprintf(str, "Msg sent: %u, %u", msg, status); // OLED_puts(0, 0, 0xff, font6x9, str); msg_destroy(msg); }
static void * worker_run(void *arg) { worker_t *w = (worker_t *) arg; msg_t *msg; int continue_running = 1; ERL_NIF_TERM answer; w->alive = 1; while(continue_running) { msg = queue_pop(w->q); if(msg->type == msg_stop) { continue_running = 0; } else { answer = make_answer(msg, evaluate_msg(msg, w)); // printf("%d receive\n", w->id); enif_send(NULL, &(msg->pid), msg->env, answer); } if(msg->res!=NULL) { enif_release_resource(msg->res); } msg_destroy(msg); } w->alive = 0; return NULL; }
/** Start OPTIONS keepalive or contact validation process */ void outbound_start_keepalive(outbound_t *ob, nta_outgoing_t *register_transaction) { unsigned interval = 0; int need_to_validate, udp; if (!ob) return; udp = ob->ob_via && ob->ob_via->v_protocol == sip_transport_udp; if (/* ob->ob_prefs.natify && */ /* On UDP, use OPTIONS keepalive by default */ (udp ? ob->ob_prefs.okeepalive != 0 /* Otherwise, only if requested */ : ob->ob_prefs.okeepalive > 0)) interval = ob->ob_prefs.interval; need_to_validate = ob->ob_prefs.validate && !ob->ob_validated; if (!register_transaction || !(need_to_validate || interval != 0)) { outbound_stop_keepalive(ob); return; } if (ob->ob_keepalive.timer) su_timer_destroy(ob->ob_keepalive.timer), ob->ob_keepalive.timer = NULL; if (interval) { su_duration_t max_defer; max_defer = su_root_get_max_defer(ob->ob_root); if ((su_duration_t)interval >= max_defer) { interval -= max_defer - 100; } ob->ob_keepalive.timer = su_timer_create(su_root_task(ob->ob_root), interval); su_timer_deferrable(ob->ob_keepalive.timer, 1); } ob->ob_keepalive.interval = interval; if (!ob->ob_validated && ob->ob_keepalive.sipstun && 0 /* Stun is disabled for now */) { nta_tport_keepalive(register_transaction); } else { if (register_transaction) { msg_t *msg = nta_outgoing_getrequest(register_transaction); sip_t const *register_request = sip_object(msg); create_keepalive_message(ob, register_request); msg_destroy(msg); } keepalive_options(ob); } }
/** @internal Send a keepalive OPTIONS that probes the registration */ static int keepalive_options_with_registration_probe(outbound_t *ob) { msg_t *req; sip_t *sip; void *request_uri; if (ob->ob_keepalive.orq) return 0; req = msg_copy(ob->ob_keepalive.msg); if (!req) return -1; sip = sip_object(req); assert(sip); request_uri = sip->sip_to->a_url; if (nta_msg_request_complete(req, nta_default_leg(ob->ob_nta), SIP_METHOD_OPTIONS, request_uri) < 0) return msg_destroy(req), -1; if (ob->ob_keepalive.auc[0]) auc_authorization(ob->ob_keepalive.auc, req, (void *)sip, "OPTIONS", request_uri, sip->sip_payload); ob->ob_keepalive.orq = nta_outgoing_mcreate(ob->ob_nta, response_to_keepalive_options, ob, NULL, req, TAG_IF(ob->ob_proxy_override, NTATAG_DEFAULT_PROXY(ob->ob_proxy)), SIPTAG_SUBJECT_STR("REGISTRATION PROBE"), /* NONE is used to remove Max-Forwards: 0 found in ordinary keepalives */ SIPTAG_MAX_FORWARDS(SIP_NONE), TAG_END()); if (!ob->ob_keepalive.orq) return msg_destroy(req), -1; ob->ob_keepalive.validating = 1; ob->ob_keepalive.validated = 0; return 0; }
static void mqtt_socket_sent(void *arg) { NODE_DBG("enter mqtt_socket_sent.\n"); struct espconn *pesp_conn = arg; if(pesp_conn == NULL) return; lmqtt_userdata *mud = (lmqtt_userdata *)pesp_conn->reverse; if(mud == NULL) return; if(!mud->connected) return; // call mqtt_sent() mud->event_timeout = 0; mud->keep_alive_tick = 0; if(mud->connState == MQTT_CONNECT_SENDING){ mud->connState = MQTT_CONNECT_SENT; // MQTT_CONNECT not queued. return; } NODE_DBG("sent1, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); // qos = 0, publish and forgot. msg_queue_t *node = msg_peek(&(mud->mqtt_state.pending_msg_q)); if(node && node->msg_type == MQTT_MSG_TYPE_PUBLISH && node->publish_qos == 0) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); if(mud->cb_puback_ref == LUA_NOREF) return; if(mud->self_ref == LUA_NOREF) return; if(mud->L == NULL) return; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_puback_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); // pass the userdata to callback func in lua lua_call(mud->L, 1, 0); } else if(node && node->msg_type == MQTT_MSG_TYPE_PUBACK && node->publish_qos == 1) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } else if(node && node->msg_type == MQTT_MSG_TYPE_PUBCOMP) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } else if(node && node->msg_type == MQTT_MSG_TYPE_PINGREQ) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } NODE_DBG("sent2, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); NODE_DBG("leave mqtt_socket_sent.\n"); }
/* * Try to deliver message to internal or smscconn queue * and generate ack/nack for smsbox connections. */ static void deliver_sms_to_queue(Msg *msg, Boxc *conn) { Msg *mack; int rc; /* * save modifies ID and time, so if the smsbox uses it, save * it FIRST for the reply message!!! */ mack = msg_create(ack); gw_assert(mack != NULL); uuid_copy(mack->ack.id, msg->sms.id); mack->ack.time = msg->sms.time; store_save(msg); rc = smsc2_rout(msg, 0); switch(rc) { case SMSCCONN_SUCCESS: mack->ack.nack = ack_success; break; case SMSCCONN_QUEUED: mack->ack.nack = ack_buffered; break; case SMSCCONN_FAILED_DISCARDED: /* no router at all */ case SMSCCONN_FAILED_QFULL: /* queue full */ warning(0, "Message rejected by bearerbox, %s!", (rc == SMSCCONN_FAILED_DISCARDED) ? "no router" : "queue full"); /* * first create nack for store-file, in order to delete * message from store-file. */ store_save_ack(msg, (rc == SMSCCONN_FAILED_QFULL ? ack_failed_tmp : ack_failed)); mack->ack.nack = (rc == SMSCCONN_FAILED_QFULL ? ack_failed_tmp : ack_failed); /* destroy original message */ msg_destroy(msg); break; } /* put ack into incoming queue of conn */ send_msg(conn, mack); msg_destroy(mack); }