static void tty_vt100_main (void) { if (uip_connected()) STATE->send_all = 1; if (uip_acked()) { if (STATE->send_all) STATE->send_all = 0; STATE->acked = STATE->sent; } if (uip_newdata ()) { uint8_t len = uip_len; for (uint8_t i = 0; i < len; i ++) { int8_t ch = ((char *) uip_appdata)[i]; if (ch == 12) /* C-l, retransmit everything. */ { STATE->send_all = 1; continue; } _getch_queue (ch); } } if (uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { /* Send new data, if any. */ if (STATE->send_all) tty_vt100_send_all (); else { /* we're just sending an update, ... */ if (vt100_head > STATE->acked) { uint8_t len = vt100_head - STATE->acked; memcpy (uip_sappdata, STATE->acked, len); uip_send (uip_sappdata, len); } else if (vt100_head < STATE->acked) { /* vt100_head wrapped around, let's be careful. */ uint8_t len = vt100_end - STATE->acked; memcpy (uip_sappdata, STATE->acked, len); uint8_t len2 = vt100_head - vt100_buf; memcpy (uip_sappdata + len, vt100_buf, len2); uip_send (uip_sappdata, len + len2); } STATE->sent = vt100_head; } } }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { tcp_markconn(uip_conn, &s); buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; shell_start(); } if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { closed(); } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); } }
//这是一个TCP 服务器应用回调函数。 //该函数通过UIP_APPCALL(tcp_demo_appcall)调用,实现Web Server的功能. //当uip事件发生时,UIP_APPCALL函数会被调用,根据所属端口(1200),确定是否执行该函数。 //例如 : 当一个TCP连接被创建时、有新的数据到达、数据已经被应答、数据需要重发等事件 void tcp_server_demo_appcall(void) { struct tcp_demo_appstate *s = (struct tcp_demo_appstate *)&uip_conn->appstate; if(uip_aborted())tcp_server_aborted(); //连接终止 if(uip_timedout())tcp_server_timedout(); //连接超时 if(uip_closed())tcp_server_closed(); //连接关闭 if(uip_connected())tcp_server_connected(); //连接成功 if(uip_acked())tcp_server_acked(); //发送的数据成功送达 //接收到一个新的TCP数据包 if (uip_newdata())//收到客户端发过来的数据 { if((tcp_server_sta&(1<<6))==0)//还未收到数据 { if(uip_len>199) { ((uint8_t*)uip_appdata)[199]=0; } strcpy((char*)tcp_server_databuf,uip_appdata); tcp_server_sta|=1<<6;//表示收到客户端数据 } }else if(tcp_server_sta&(1<<5))//有数据需要发送 { s->textptr=tcp_server_databuf; s->textlen=strlen((const char*)tcp_server_databuf); tcp_server_sta&=~(1<<5);//清除标记 } //当需要重发、新数据到达、数据包送达、连接建立时,通知uip发送数据 if(uip_rexmit()||uip_newdata()||uip_acked()||uip_connected()||uip_poll()) { tcp_server_senddata(); } }
static void irc_main(void) { if (uip_aborted() || uip_timedout()) { IRCDEBUG ("connection aborted\n"); irc_conn = NULL; } if (uip_closed()) { IRCDEBUG ("connection closed\n"); irc_conn = NULL; } if (uip_connected()) { IRCDEBUG ("new connection\n"); STATE->stage = IRC_SEND_USERNICK; STATE->sent = IRC_SEND_INIT; #ifdef ECMD_IRC_SUPPORT STATE->reparse = 0; #endif *STATE->outbuf = 0; } if (STATE->stage == IRC_SEND_JOIN && uip_acked ()) STATE->stage ++; else if (STATE->stage == IRC_CONNECTED && uip_acked ()) { *STATE->outbuf = 0; #ifdef ECMD_IRC_SUPPORT if (STATE->reparse) irc_handle_ecmd (); #endif } else if (uip_newdata() && uip_len) { ((char *) uip_appdata)[uip_len] = 0; IRCDEBUG ("received data: %s\n", uip_appdata); if (irc_parse ()) { uip_close (); /* Parse error */ return; } } if (uip_rexmit ()) irc_send_data (STATE->sent); else if ((STATE->stage > STATE->sent || STATE->stage == IRC_CONNECTED) && (uip_newdata() || uip_acked() || uip_connected())) irc_send_data (STATE->stage); else if (STATE->stage == IRC_CONNECTED && uip_poll() && *STATE->outbuf) irc_send_data (STATE->stage); }
void httpd_main(void) { if (uip_aborted() || uip_timedout()) { printf("httpd: connection aborted\n"); httpd_cleanup(); return; } if (uip_closed()) { printf("httpd: connection closed\n"); httpd_cleanup(); return; } if (uip_connected()) { printf("httpd: new connection\n"); /* initialize struct */ STATE->handler = NULL; STATE->header_acked = 0; STATE->eof = 0; STATE->header_reparse = 0; #ifdef HTTPD_AUTH_SUPPORT STATE->auth_state = PAM_UNKOWN; #endif } if (uip_newdata() && (!STATE->handler || STATE->header_reparse)) { printf("httpd: new data\n"); httpd_handle_input(); } #ifdef HTTPD_AUTH_SUPPORT if (STATE->auth_state == PAM_DENIED && STATE->handler != httpd_handle_401) { httpd_cleanup(); STATE->handler = httpd_handle_401; STATE->header_reparse = 0; printf("httpd: auth failed\n"); } else if (STATE->auth_state == PAM_PENDING) return; /* Waiting for the PAM Layer */ #endif if (uip_rexmit() || uip_newdata() || uip_acked() || uip_poll() || uip_connected()) { /* Call associated handler, if set already. */ if (STATE->handler && (!STATE->header_reparse)) STATE->handler(); } }
static void jabber_main(void) { if (uip_aborted() || uip_timedout()) { JABDEBUG("connection aborted\n"); jabber_conn = NULL; } if (uip_closed()) { JABDEBUG("connection closed\n"); jabber_conn = NULL; } if (uip_connected()) { JABDEBUG("new connection\n"); STATE->stage = JABBER_OPEN_STREAM; STATE->sent = JABBER_INIT; #ifdef JABBER_STARTUP_MESSAGE_SUPPORT strncpy_P(STATE->target, PSTR(CONF_JABBER_BUDDY), sizeof(STATE->target)); strncpy_P(STATE->outbuf, jabber_startup_text, sizeof(STATE->outbuf)); STATE->action = JABBER_ACTION_MESSAGE; #endif /* JABBER_STARTUP_MESSAGE_SUPPORT */ } if (uip_acked() && STATE->stage == JABBER_CONNECTED) { STATE->action = JABBER_ACTION_NONE; *STATE->outbuf = 0; } if (uip_newdata() && uip_len) { /* Zero-terminate */ ((char *) uip_appdata)[uip_len] = 0; JABDEBUG("received data: %s\n", uip_appdata); if (jabber_parse()) { uip_close(); /* Parse error */ return; } } if (uip_rexmit()) jabber_send_data(STATE->stage, STATE->action); else if ((STATE->stage > STATE->sent || STATE->stage == JABBER_CONNECTED) && (uip_newdata() || uip_acked() || uip_connected())) jabber_send_data(STATE->stage, STATE->action); else if (STATE->stage == JABBER_CONNECTED && uip_poll() && STATE->action) jabber_send_data(STATE->stage, STATE->action); }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { if(!connected) { buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; connected = 1; shell_start(); timer_set(&s.silence_timer, MAX_SILENCE_TIME); ts = (char *)0; } else { uip_send(telnetd_reject_text, strlen(telnetd_reject_text)); ts = (char *)1; } tcp_markconn(uip_conn, ts); } if(!ts) { if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { shell_stop(); connected = 0; } if(uip_acked()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); acked(); } if(uip_newdata()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); if(s.numsent > 0) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); } } if(uip_poll()) { if(timer_expired(&s.silence_timer)) { uip_close(); tcp_markconn(uip_conn, NULL); } } } }
static void mysql_main(void) { if (uip_aborted() || uip_timedout()) { MYDEBUG ("connection aborted\n"); mysql_conn = NULL; } if (uip_closed()) { MYDEBUG ("connection closed\n"); mysql_conn = NULL; } if (uip_connected()) { MYDEBUG ("new connection\n"); STATE->stage = MYSQL_WAIT_GREETING; STATE->sent = MYSQL_WAIT_GREETING; STATE->packetid = 0; } if (uip_newdata() && uip_len) { #ifdef DEBUG_MYSQL MYDEBUG ("received data: %s\n", uip_appdata); for (uint16_t i = 0; i < uip_len; i ++) debug_putchar (((unsigned char *) uip_appdata)[i]); debug_putchar (10); #endif if (mysql_parse ()) { uip_close (); /* Parse error */ return; } } if (uip_rexmit()) { STATE->packetid --; mysql_send_data (STATE->sent); } else if ((STATE->stage > STATE->sent || STATE->stage == MYSQL_CONNECTED) && (uip_newdata() || uip_acked() || uip_connected())) mysql_send_data (STATE->stage); else if (STATE->stage == MYSQL_CONNECTED && uip_poll() && *STATE->u.stmtbuf) mysql_send_data(STATE->stage); }
static void contiki_appcall(void *data) { contiki_data_t *s = (contiki_data_t *)data; if (uip_closed() || uip_aborted() || uip_timedout()) { //xprintf("closed or aborted or timedout\n"); if (s->state == READING || s->state == WRITTING) { s->state = ERROR; } else { s->state = CLOSED; } process_post_synch(s->process, xively_event, s); } else if (uip_connected()) { s->state = CONNECTED; PSOCK_INIT(&s->p, NULL, 0); process_post_synch(s->process, xively_event, s); } else if (uip_newdata()) { if (s->state == READING) { s->state = READ_END; process_post_synch(s->process, xively_event, s); } } if (s->state == CLOSING) { uip_close(); } handle_output(s); }
static int hello_world_appcall(void) { struct tcp_hello_appstate *s = &(uip_conn->appstate.tcp_hello); if(uip_connected()) { PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer)); } PSOCK_BEGIN(&s->p); PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n"); PSOCK_READTO(&s->p, '\n'); strncpy(s->name, s->inputbuffer, sizeof(s->name)); s->name[strlen(s->name)-2] = 0; PSOCK_SEND_STR(&s->p, "Hello "); PSOCK_SEND_STR(&s->p, s->name); PSOCK_SEND_STR(&s->p, " !\n"); sprintf(s->name, "r %d/%d", nrf_link_get_rx_packets(), nrf_link_get_rx_dropped()); PSOCK_SEND_STR(&s->p, s->name); PSOCK_SEND_STR(&s->p, " "); sprintf(s->name, "t %d/%d", nrf_link_get_tx_packets(), nrf_link_get_tx_dropped()); PSOCK_SEND_STR(&s->p, s->name); PSOCK_SEND_STR(&s->p, "\n\r"); PSOCK_CLOSE(&s->p); PSOCK_END(&s->p); }
/*---------------------------------------------------------------------*/ static void uipcall(void *state) { if(uip_udpconnection()) { recv_udpthread(&s.recv_udpthread_pt); send_udpthread(&s.udpthread_pt); } else { if(uip_conn->lport == HTONS(CODEPROP_DATA_PORT)) { if(uip_connected()) { if(state == NULL) { s.addr = 0; s.count = 0; PT_INIT(&s.tcpthread_pt); process_poll(&codeprop_process); tcp_markconn(uip_conn, &s); /* process_post(PROCESS_BROADCAST, codeprop_event_quit, */ /* (process_data_t)NULL); */ } else { PRINTF(("codeprop: uip_connected() and state != NULL\n")); uip_abort(); } } recv_tcpthread(&s.tcpthread_pt); if(uip_closed() || uip_aborted() || uip_timedout()) { PRINTF(("codeprop: connection down\n")); tcp_markconn(uip_conn, NULL); } } } }
PROCESS_THREAD(server_process, ev, data) { PROCESS_BEGIN(); set_global_address(); leds_init(); print_local_addresses(); printf("Starting TCP server on port=%d\n", PORT); tcp_listen(UIP_HTONS(PORT)); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if(uip_aborted() ) printf("TCP aborted\n"); if(uip_timedout() ) printf("TCP timeoutn\n"); if(uip_closed() ) printf("TCP closed\n"); if(uip_connected()) { printf("TCP Connected\n\r"); PSOCK_INIT(&ps, buf, sizeof(buf)); while(!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); handle_connection(&ps); } } } PROCESS_END(); }
void uip_task_appcall() { if(uip_connected()) { socket_process_new_connect_(); }else if(uip_poll()) { if(uip_stopped(uip_conn)) { socket_process_try_restart_(); } socket_process_write_(); }else if(uip_newdata()) { socket_process_new_data_(); socket_process_write_(); }else if(uip_aborted() || uip_closed()) { socket_process_close_(); }else if(uip_timedout()) { socket_process_timeout_(); uip_close(); }else if(uip_acked() || uip_rexmit()) { socket_process_write_(); } }
/* -------------------------------------------------------------------------- */ PROCESS_THREAD(example_psock_server_process, ev, data) { // The Start... PROCESS_BEGIN(); // So, here we configure the network listening at a TCP port. tcp_listen(UIP_HTONS(12345)); while (1) { // Wait a TCP / IP event... PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); // If someone has connected, let's init the connection if (uip_connected()) { // Bind the buffer to the socket PSOCK_INIT(&socket, buffer, sizeof(buffer)); // So now, let's keep the connection open waiting for something while (!(uip_aborted() || uip_closed() || uip_timedout())) { // Wait for an TCIP / IP event PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); // And then, let's send to handle the data handle_connection(&socket); } } } // ... the End PROCESS_END(); }
/* * In hello-world.h we have defined the UIP_APPCALL macro to * hello_world_appcall so that this funcion is uIP's application * function. This function is called whenever an uIP event occurs * (e.g. when a new connection is established, new data arrives, sent * data is acknowledged, data needs to be retransmitted, etc.). */ void hello_world_appcall(void) { /* * The uip_conn structure has a field called "appstate" that holds * the application state of the connection. We make a pointer to * this to access it easier. */ struct hello_world_state *s = &(uip_conn->appstate); /* * If a new connection was just established, we should initialize * the protosocket in our applications' state structure. */ if(uip_connected()) { PSOCK_INIT(&p, s->inputbuffer, sizeof(s->inputbuffer)); } /* * Finally, we run the protosocket function that actually handles * the communication. We pass it a pointer to the application state * of the current connection. */ handle_connection(s); }
void lp_tcp_appcall(void) { struct lp_tcp_state *s; s = &(uip_conn->appstate); if (uip_connected()) { s->state = WELCOME_SENT; uip_send("Handshake complete!\n", 20); return; } if (uip_acked() && s->state == WELCOME_SENT) { s->state = WELCOME_ACKED; } if (uip_newdata()) { P1OUT ^= BIT0; uip_send("Received packet\n", 16); } if (uip_rexmit()) { switch(s->state) { case WELCOME_SENT: uip_send("Handshake complete!\n", 20); break; case WELCOME_ACKED: uip_send("Received packet\n", 16); break; } } }
/* * In socketapp.h we have defined the UIP_APPCALL macro to * socket_app_appcall so that this function is uIP's application * function. This function is called whenever an uIP event occurs * (e.g. when a new connection is established, new data arrives, sent * data is acknowledged, data needs to be retransmitted, etc.). */ void socket_app_appcall() { /* * The uip_conn structure has a field called "appstate" that holds * the application state of the connection. We make a pointer to * this to access it easier. */ struct socket_app_state *s = &(uip_conn->appstate); // Serial.print("uip_flags:"); // Serial.println(uip_flags); // Serial.print("psock state:"); // Serial.println((&s->p)->state); /* * If a new connection was just established, we should initialize * the protosocket in our applications' state structure. */ if(uip_connected()) { Serial.println("connected"); PSOCK_INIT(&s->p, (unsigned char*)(s->inputbuffer), sizeof(s->inputbuffer)); // Serial.println("psock_init"); } /* * Finally, we run the protosocket function that actually handles * the communication. We pass it a pointer to the application state * of the current connection. */ Serial.println("before handle_connections"); handle_connection(s); Serial.println("after handle_connections"); }
void uip_modbus_appcall(void) { if(uip_connected()) { PRINTF("connected!\r\n"); } if(uip_closed()) { PRINTF("closed\r\n"); } if(uip_newdata()) { PRINTF("request!\r\n"); // 获得modbus请求 memcpy(ucTCPRequestFrame, uip_appdata, uip_len ); ucTCPRequestLen = uip_len; // 向 modbus poll发送消息 xMBPortEventPost( EV_FRAME_RECEIVED ); } if(uip_poll()) { if(bFrameSent) { bFrameSent = FALSE; // uIP发送Modbus应答数据包 uip_send( ucTCPResponseFrame , ucTCPResponseLen ); } } }
void example2_app(void) { struct example2_state *s; s = (struct example2_state *)uip_conn->appstate; if(uip_connected()) { s->state = WELCOME_SENT; uip_send("Welcome!\n", 9); return; } if(uip_acked() && s->state == WELCOME_SENT) { s->state = WELCOME_ACKED; } if(uip_newdata()) { uip_send("ok1\n", 4); led_on(); // while(1); led_off(); } if(uip_rexmit()) { switch(s->state) { case WELCOME_SENT: uip_send("Welcome!\n", 9); break; case WELCOME_ACKED: uip_send("ok2\n", 4); break; } } }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(tcp_loader_process, ev, data) { PROCESS_BEGIN(); tcp_listen(HTONS(CODEPROP_DATA_PORT)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event && uip_conn->lport == HTONS(CODEPROP_DATA_PORT)) { if(uip_connected()) { /* Really uip_connecting()!!! */ if(data == NULL) { PT_INIT(&s.tcpthread_pt); process_poll(&tcp_loader_process); tcp_markconn(uip_conn, &s); } else { PRINTF(("codeprop: uip_connected() and data != NULL\n")); uip_abort(); } } recv_tcpthread(&s.tcpthread_pt); /* Run thread */ if(uip_closed() || uip_aborted() || uip_timedout()) { PRINTF(("codeprop: connection down\n")); tcp_markconn(uip_conn, NULL); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_psock_client_process, ev, data) { uip_ipaddr_t addr; printf("%d\n", TEST); PROCESS_BEGIN(); uip_ipaddr(addr, 192,168,2,1); tcp_connect(addr, UIP_HTONS(80), NULL); printf("Connecting...\n"); PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if(uip_aborted() || uip_timedout() || uip_closed()) { printf("Could not establish connection\n"); } else if(uip_connected()) { printf("Connected\n"); PSOCK_INIT(&ps, buffer, sizeof(buffer)); do { handle_connection(&ps); PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); } while(!(uip_closed() || uip_aborted() || uip_timedout())); printf("\nConnection closed.\n"); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(server_process, ev, data) { PROCESS_BEGIN(); u16_t hostport = 7777; printf("TCP listen on %d.%d.%d.%d:%u\n", uip_ipaddr_to_quad(&uip_hostaddr), hostport); tcp_listen(uip_htons(hostport)); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if (uip_connected()) { printf("server: client arrived!\n"); connected = 1; while (!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); } if (uip_aborted() || uip_closed()) { connected = 0; } } else { printf("server: client not accepted!\n"); KLEENET_ASSERT(0 && "server: client not accepted!\n"); } } PROCESS_END(); }
/* * In socketapp.h we have defined the UIP_APPCALL macro to * socket_app_appcall so that this function is uIP's application * function. This function is called whenever an uIP event occurs * (e.g. when a new connection is established, new data arrives, sent * data is acknowledged, data needs to be retransmitted, etc.). */ void socket_app_appcall(void) { /* * The uip_conn structure has a field called "appstate" that holds * the application state of the connection. We make a pointer to * this to access it easier. */ struct socket_app_state *s = &(uip_conn->appstate); /* * If a new connection was just established, we should initialize * the protosocket in our applications' state structure. */ if(uip_connected()) { //memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer)); PSOCK_INIT(&s->p, (uint8_t*)s->inputbuffer, SOCKET_BUFFER_LENGTH // sizeof((uint8_t*)s->inputbuffer) ); } /* * Finally, we run the protosocket function that actually handles * the communication. We pass it a pointer to the application state * of the current connection. */ handle_connection(s); }
void ems_net_main(void) { if (uip_connected()) { if (ems_conn == NULL) { ems_conn = uip_conn; uip_conn->wnd = EMS_BUFFER_LEN - 1; } else { /* if we have already an connection, send an error */ uip_send("ERROR: Connection blocked\n", 27); } } else if (uip_acked()) { /* If the peer is not our connection, close it */ if (ems_conn != uip_conn) { uip_close(); } else { /* Some data we have sent was acked, jipphie */ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ems_recv_buffer.len -= ems_recv_buffer.sent; memmove(ems_recv_buffer.data, ems_recv_buffer.data + ems_recv_buffer.sent, ems_recv_buffer.len); } } } else if (uip_closed() || uip_aborted() || uip_timedout()) {
PROCESS_THREAD(tcp_process, ev, data) { static char incoming[10]; static struct psock ps; PROCESS_BEGIN(); uart0_set_br(1000000); tcp_listen(UIP_HTONS(2020)); while(1) { PROCESS_YIELD(); } { /* wait for tcp connection */ PROCESS_WAIT_EVENT_UNTIL(ev==tcpip_event && uip_connected()); /* start estimator process and init psock connection handler */ process_start(&ahrs_process, NULL); PSOCK_INIT(&ps,incoming,sizeof(incoming)); /* loop until connection is closed */ while (!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_YIELD_UNTIL(ev==tcpip_event); handle_connection(&ps); } /* stop ahrs process */ process_exit(&ahrs_process); } PROCESS_END(); }
/* * The definition of the process. */ PROCESS_THREAD(sensor_psock_server_process, ev, data) { PROCESS_BEGIN(); tcp_listen(UIP_HTONS(1010)); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if(uip_connected()) { PSOCK_INIT(&ps, buffer, sizeof(buffer)); while(!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); handle_connection(&ps); } PSOCK_CLOSE(&ps); } } PSOCK_CLOSE_EXIT(&ps); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void httpd_appcall(void) { struct httpd_state *s = (struct httpd_state *)&(uip_conn->appstate); if(uip_closed() || uip_aborted() || uip_timedout()) { } else if(uip_connected()) { PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1); PT_INIT(&s->outputpt); s->state = STATE_WAITING; /* timer_set(&s->timer, CLOCK_SECOND * 100);*/ s->timer = 0; handle_connection(s); } else if(s != NULL) { if(uip_poll()) { ++s->timer; if(s->timer >= 20) { uip_abort(); } } else { s->timer = 0; } handle_connection(s); } else { uip_abort(); } }
/*DISPATCHER_UIPCALL(smtp_appcall, state)*/ void smtp_appcall(void *state) { if(uip_connected()) { /* senddata();*/ return; } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(); } else if(uip_poll()) { senddata(); } /* if(uip_closed()) { printf("Dnoe\n"); }*/ }
/*-----------------------------------------------------------------------------------*/ void ctk_vncserver_appcall(void *state) { static struct vnc_server_state *vs; vs = (struct vnc_server_state *)(state); if(uip_connected()) { /* Since we've just been connected, the state pointer should be NULL and we need to allocate a new state object. If we have run out of memory for state objects, we'll have to abort the connection and return. */ if(vs == NULL) { vs = alloc_state(); if(vs == NULL) { uip_close(); return; } tcp_markconn(uip_conn, (void *)vs); } } else if(uip_closed() || uip_aborted()) { if(vs != NULL) { dealloc_state(vs); } return; } vnc_server_appcall(vs); }
/*---------------------------------------------------------------------------*/ void httpd_appcall(void *state) { struct httpd_state *s = (struct httpd_state *)state; if(uip_closed() || uip_aborted() || uip_timedout()) { if(s != NULL) { memb_free(&conns, s); } } else if(uip_connected()) { s = (struct httpd_state *)memb_alloc(&conns); if(s == NULL) { uip_abort(); return; } tcp_markconn(uip_conn, s); PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1); PT_INIT(&s->outputpt); s->state = STATE_WAITING; timer_set(&s->timer, CLOCK_SECOND * 10); handle_connection(s); } else if(s != NULL) { if(uip_poll()) { if(timer_expired(&s->timer)) { uip_abort(); } } else { timer_reset(&s->timer); } handle_connection(s); } else { uip_abort(); } }