void modem_output_thread(void *args) { int wr; int ret; int sent; BOOL monitor_dsr=TRUE; SetThreadName("Modem Output"); conn_api.output_thread_running=1; if(args != NULL) { if((comGetModemStatus(com)&COM_DSR) == 0) monitor_dsr=FALSE; } while(com != COM_HANDLE_INVALID && !conn_api.terminate) { pthread_mutex_lock(&(conn_outbuf.mutex)); wr=conn_buf_wait_bytes(&conn_outbuf, 1, 100); if(wr) { wr=conn_buf_get(&conn_outbuf, conn_api.wr_buf, conn_api.wr_buf_size); pthread_mutex_unlock(&(conn_outbuf.mutex)); sent=0; while(sent < wr) { ret=comWriteBuf(com, conn_api.wr_buf+sent, wr-sent); sent+=ret; if(ret==COM_ERROR) break; } if(ret==COM_ERROR) { } } else pthread_mutex_unlock(&(conn_outbuf.mutex)); if(args==NULL) { if((comGetModemStatus(com)&COM_DCD) == 0) break; } else if(monitor_dsr) { if((comGetModemStatus(com)&COM_DSR) == 0) break; } } conn_api.output_thread_running=0; }
BOOL handle_call(void) { BYTE buf[4096]; BYTE telnet_buf[sizeof(buf)]; BYTE* p; int result; int rd; int wr; fd_set socket_set; struct timeval tv = {0, 0}; bytes_sent=0; bytes_received=0; call_terminated=FALSE; /* Reset Telnet state information */ telnet_cmdlen=0; ZERO_VAR(telnet_local_option); ZERO_VAR(telnet_remote_option); if(telnet && telnet_advertise_cid && (cid_number[0] || cid_name[0])) /* advertise the ability to send our location */ send_telnet_cmd(TELNET_WILL, TELNET_SEND_LOCATION); input_thread_terminated=FALSE; _beginthread(input_thread, 0, NULL); while(!terminated) { if(!dcd_ignore && !carrier_detect(com_handle)) { lprintf(LOG_WARNING,"Loss of Carrier Detect (DCD) detected"); break; } #if 0 /* single-threaded mode: */ if(comReadByte(com_handle, &ch)) { lprintf(LOG_DEBUG,"read byte: %c", ch); send(sock, &ch, sizeof(ch), 0); } #endif FD_ZERO(&socket_set); FD_SET(sock,&socket_set); if((result = select(sock+1,&socket_set,NULL,NULL,&tv)) == 0) { YIELD(); continue; } if(result == SOCKET_ERROR) { lprintf(LOG_ERR,"SOCKET ERROR %u on select", ERROR_VALUE); break; } rd=recv(sock,buf,sizeof(buf),0); if(rd < 1) { if(rd==0) { lprintf(LOG_WARNING,"Socket Disconnected"); break; } if(ERROR_VALUE == EAGAIN) continue; else if(ERROR_VALUE == ENOTSOCK) lprintf(LOG_WARNING,"Socket closed by peer on receive"); else if(ERROR_VALUE==ECONNRESET) lprintf(LOG_WARNING,"Connection reset by peer on receive"); else if(ERROR_VALUE==ESHUTDOWN) lprintf(LOG_WARNING,"Socket shutdown on receive"); else if(ERROR_VALUE==ECONNABORTED) lprintf(LOG_WARNING,"Connection aborted by peer on receive"); else lprintf(LOG_ERR,"SOCKET RECV ERROR %d",ERROR_VALUE); break; } if(telnet) p=telnet_interpret(buf,rd,telnet_buf,&rd); else p=buf; if((wr=comWriteBuf(com_handle, p, rd)) != COM_ERROR) bytes_sent += wr; } call_terminated=TRUE; /* terminate input_thread() */ while(!input_thread_terminated) { YIELD(); } lprintf(LOG_INFO,"Bytes sent-to, received-from COM Port: %lu, %lu" ,bytes_sent, bytes_received); return TRUE; }
/* * TODO: This seem kinda dangerous for short writes... */ int COMIOCALL comWriteString(COM_HANDLE handle, const char* str) { return comWriteBuf(handle, (BYTE*)str, strlen(str)); }
int comWriteString(COM_HANDLE handle, const char* str) { return comWriteBuf(handle, str, strlen(str)); }