/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); dtls_init(); init_dtls(); print_local_addresses(); if (!dtls_context) { dtls_emerg("cannot create context\n"); PROCESS_EXIT(); } #ifdef ENABLE_POWERTRACE powertrace_start(CLOCK_SECOND * 2); #endif while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { dtls_handle_read(dtls_context); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); print_local_addresses(); dtls_init(); init_dtls(); if (!dtls_context) { dsrv_log(LOG_EMERG, "cannot create context\n"); PROCESS_EXIT(); } while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { dtls_handle_read(dtls_context); } #if 0 if (bytes_read > 0) { /* dtls_handle_message(dtls_context, &the_session, readbuf, bytes_read); */ read_from_peer(dtls_context, &the_session, readbuf, bytes_read); } dtls_handle_message(ctx, &session, uip_appdata, bytes_read); #endif } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(dtls_echo_server_process, ev, data) { PROCESS_BEGIN(); init_dtls(); if (!dtls_context) { dsrv_log(DTLS_LOG_EMERG, "cannot create context\n"); PROCESS_EXIT(); } while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { dtls_handle_read(dtls_context); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { static int connected = 0; static session_t dst; PROCESS_BEGIN(); dtls_init(); init_dtls(&dst); serial_line_init(); if (!dtls_context) { dsrv_log(LOG_EMERG, "cannot create context\n"); PROCESS_EXIT(); } while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { dtls_handle_read(dtls_context); } else if (ev == serial_line_event_message) { register size_t len = min(strlen(data), sizeof(buf) - buflen); memcpy(buf + buflen, data, len); buflen += len; if (buflen < sizeof(buf) - 1) buf[buflen++] = '\n'; /* serial event does not contain LF */ } if (buflen) { if (!connected) connected = dtls_connect(dtls_context, &dst) >= 0; try_send(dtls_context, &dst); } } PROCESS_END(); }