bool OpenIO (CTCPIPSystemDrvr* pTCPIPSystem, char* object_ref) { bool sts = false; RESET_ERRORS((long)pTCPIPSystem); if (gDrvrGlobal.gTCPIPLoadError != 0) { SET_ERROR((long)pTCPIPSystem, PC, TCPIP, UNKNOWN_API, E_DRIVER, gDrvrGlobal.gTCPIPLibrary, O_INIT_PROCESS, F_LOAD_DLL, gDrvrGlobal.gTCPIPLoadError, (int)0); sts = false; } else { RESET_ERRORS((long)pTCPIPSystem); sts = (gDrvrGlobal.fpTCPIPOpenSession)((void*)pTCPIPSystem, object_ref); } return sts; }
int WRITE_TCPIP_RESPONSE(CTCPIPSystemSrvr* pnode, unsigned long message_length) { HEADER* hdr; char* buffer; short length; unsigned long total_length; total_length = message_length; short retcode = 0; short tx_handle[10]; memset(&tx_handle[0],0,20); retcode = TMF_GETTXHANDLE_(&tx_handle[0]); if (retcode == 0) TMF_BEGINTAG_FROM_TXHANDLE_(&tx_handle[0], &pnode->m_trans_begin_tag); else pnode->m_trans_begin_tag = 0; RESET_ERRORS((long)pnode); buffer = pnode->m_wbuffer; hdr = (HEADER*)pnode->m_wbuffer; memcpy(hdr, &pnode->m_rhdr, sizeof(HEADER)); hdr->total_length = message_length - sizeof(HEADER); if (hdr->compress_ind == COMP_YES && hdr->total_length > MIN_LENGTH_FOR_COMPRESSION) { total_length -= sizeof(HEADER); DoCompression(pnode, hdr, (unsigned char*)(buffer+sizeof(HEADER)), (unsigned long&)total_length); total_length += sizeof(HEADER); } else hdr->compress_type = 0; memcpy(&pnode->m_whdr, hdr, sizeof(HEADER)); if (hdr->swap == SWAP_YES) HEADER_swap(hdr); while (total_length > 0) { if (total_length > TCPI_SRVR_SEND_BUFFER) length = TCPI_SRVR_SEND_BUFFER; else length = total_length; if (pnode->do_write(buffer, length, WRITE_TIMEOUT)== false) { pnode->send_error(SRVR_ERR_WRITE_OPERATION,0, NULL); return 1; } total_length -= length; buffer += length; } return 0; }
CTCPIPSystemSrvr::~CTCPIPSystemSrvr() { if (m_IObuffer != NULL) delete m_IObuffer; if (m_nSocketFnum > 0) { shutdown(m_nSocketFnum, 2); FILE_CLOSE_(m_nSocketFnum); // ReleaseServer(); } RESET_ERRORS((long)this); cleanup(); }
int CNSKListener::runProgram(char* TcpProcessName, long port, int TransportTrace) { SRVRTRACE_ENTER(FILE_LSN+11); short fnum,error; _cc_status cc; if ((error = FILE_OPEN_("$RECEIVE",8,&m_ReceiveFnum, 0, 0, 1, MAX_REQUEST,0)) != 0) { // (Could not open $RECEIVE: error %d", error) SET_ERROR((long)0, NSK, UNKNOWN_TRANSPORT, UNKNOWN_API, E_LISTENER, "runProgram", O_INIT_PROCESS, F_FILE_OPEN_, error, 0); return error; } INITIALIZE_TRACE(TransportTrace); unsigned short countRead; SB_Tag_Type tag; READUPDATEX(m_ReceiveFnum, m_RequestBuf, MAX_BUFFER_LENGTH ); while(m_bKeepRunning) { RESET_ERRORS((long)0); ADD_ONE_TO_HANDLE(&m_call_id); fnum = -1; cc = AWAITIOX(&fnum,OMITREF, &countRead, &tag, -1); TRACE_INPUT(fnum,countRead,tag,cc); if (fnum == m_ReceiveFnum) { CheckReceiveMessage(cc, countRead, &m_call_id); FS_TRACE_OUTPUT(cc); } if (m_bKeepRunning) cc = READUPDATEX(m_ReceiveFnum, m_RequestBuf, MAX_BUFFER_LENGTH ); else { FILE_CLOSE_(m_ReceiveFnum); return 1; } } SRVRTRACE_EXIT(FILE_LSN+11); return 0; }
CTCPIPSystemDrvr::~CTCPIPSystemDrvr() { RESET_ERRORS((long)this); cleanup(); if (m_IObuffer != NULL) delete m_IObuffer; if (m_hSocket != -1) { closesocket(m_hSocket); } if (m_hEvents[0] != NULL) CloseHandle(m_hEvents[0]); if (m_hEvents[1] != NULL) CloseHandle(m_hEvents[1]); }
bool READ_TCPIP_REQUEST(CTCPIPSystemSrvr* pnode) { HEADER* hdr; char* buffer; short length; unsigned long total_length; RESET_ERRORS((long)pnode); length = pnode->m_rlength; if (pnode->do_read(true, hdr, buffer, length, READ_TIMEOUT)== false) { pnode->send_error(SRVR_ERR_READ_OPERATION,0, NULL); return false; } if (hdr->signature != SIGNATURE) return false; memcpy(&pnode->m_rhdr,hdr,sizeof(HEADER)); if (pnode->m_rhdr.compress_ind == COMP_YES && pnode->m_rhdr.compress_type != 0) total_length = hdr->cmp_length; else total_length = hdr->total_length; if(pnode->r_allocate(total_length) == NULL) { pnode->send_error(SRVR_ERR_MEMORY_ALLOCATE,0, NULL); return false; } memcpy(pnode->m_rbuffer, buffer, length); pnode->m_curptr = pnode->m_rbuffer + length; total_length -= length; while(total_length > 0) { if (pnode->do_read(false, hdr, buffer, length, READ_TIMEOUT)== false) { pnode->send_error(SRVR_ERR_READ_OPERATION,0, NULL); return false; } memcpy(pnode->m_curptr, buffer, length); pnode->m_curptr += length; total_length -= length; } if (pnode->m_rhdr.compress_ind == COMP_YES && pnode->m_rhdr.compress_type != 0) return DoExpand(pnode, pnode->m_rhdr, pnode->m_rbuffer, total_length); return true; }
CTCPIPSystemSrvr::~CTCPIPSystemSrvr() { SRVRTRACE_ENTER(FILE_TSS+22); if (m_IObuffer != NULL) delete m_IObuffer; if (m_nSocketFnum > 0) { // We will need to get the socket file descriptor out // of the fd watch list which select() monitors GTransport.m_listener->closeTCPIPSession(m_nSocketFnum); m_nSocketFnum = -2; } if(GTransport.m_error_list.m_list_length) RESET_ERRORS((long)this); w_release(); r_release(); GTransport.m_TCPIPSystemSrvr_list->m_current_node = NULL; SRVRTRACE_EXIT(FILE_TSS+22); // PRINTSRVRTRC }
CTCPIPUnixDrvr::CTCPIPUnixDrvr() { odbcAPI = 0; dialogueId = 0; RESET_ERRORS((long)this); m_wbuffer = NULL; m_rbuffer = NULL; m_rbuffer_length = 0; m_wbuffer_length = 0; m_object_ref[0]=0; m_IObuffer = NULL; m_IObuffer = new char[MAX_TCP_BUFFER_LENGTH]; if (m_IObuffer == NULL) exit(0); m_hSocket = NULL; m_IOCompression = 0; m_hEvents[0] = NULL; m_hEvents[1] = NULL; // we need to initalize the function pointers! // FPTCPIPInitIO fpTCPIPInitIO; gDrvrGlobal.fpTCPIPInitIO = &TCPIPInitIO; // FPTCPIPExitIO fpTCPIPExitIO; gDrvrGlobal.fpTCPIPExitIO = &TCPIPExitIO; // FPTCPIPOpenSession fpTCPIPOpenSession; gDrvrGlobal.fpTCPIPOpenSession = &TCPIPOpenSession; // FPTCPIPCloseSession fpTCPIPCloseSession; gDrvrGlobal.fpTCPIPCloseSession = &TCPIPCloseSession; // FPTCPIPDoWriteRead fpTCPIPDoWriteRead; gDrvrGlobal.fpTCPIPDoWriteRead = &TCPIPDoWriteRead; // #ifdef BIGE m_swap = SWAP_NO; #else m_swap = SWAP_YES; #endif }
CTCPIPSystemDrvr::CTCPIPSystemDrvr() { odbcAPI = 0; dialogueId = 0; RESET_ERRORS((long)this); m_wbuffer = NULL; m_rbuffer = NULL; m_rbuffer_length = 0; m_wbuffer_length = 0; m_object_ref[0]=0; m_IObuffer = NULL; m_IObuffer = new char[MAX_TCP_BUFFER_LENGTH]; if (m_IObuffer == NULL) exit(0); m_hSocket = -1; m_IOCompression = 0; m_hEvents[0] = NULL; m_hEvents[1] = NULL; m_swap = SWAP_YES; }
CTCPIPUnixDrvr::~CTCPIPUnixDrvr() { RESET_ERRORS((long)this); cleanup(); if (m_IObuffer != NULL) #ifndef unixcli delete m_IObuffer; #else delete []m_IObuffer; #endif if (m_hSocket != NULL) { #ifndef unixcli closesocket(m_hSocket); #else close(m_hSocket); #endif } if (m_hEvents[0] != NULL) CloseHandle(m_hEvents[0]); if (m_hEvents[1] != NULL) CloseHandle(m_hEvents[1]); }
void IOMessage( /* In */ CEE_tag_def objtag_ , /* In */ const CEE_handle_def *call_id_ , /* Out */ CEERCV_IOMessage_exc_ *exception_ , /* In */ const FS_Receiveinfo_Type *receiveInfo , /* In */ IDL_short dialogInfo , /* In */ const CEERCV_IOMessage_request_seq_ *request , /* Out */ IDL_short *error , /* Out */ CEERCV_IOMessage_reply_seq_ *reply ) { CEE_status sts = CEE_SUCCESS; CEE_handle_def call_id; memcpy(&call_id, call_id_, sizeof(CEE_handle_def)); char* buffer = (char *)request->_buffer + sizeof(HEADER); long length = request->_length - sizeof(HEADER); HEADER* hdr = (HEADER*)request->_buffer; CFSystemSrvr* pnode; unsigned short max_reply_count = receiveInfo->max_reply_count; short message_tag = receiveInfo->message_tag; *error = 0; exception_->exception_nr = 0; reply->_length = 0; reply->_buffer = NULL; switch(hdr->hdr_type) { case WRITE_REQUEST_FIRST: pnode = GTransport.m_FSystemSrvr_list->find_node(receiveInfo); if (pnode == NULL) { *error = SRVR_ERR_NODE_WRITE_REQUEST_FIRST; IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); return; } RESET_ERRORS((long)pnode); pnode->m_message_tag = message_tag; memset(&pnode->m_whdr,0,sizeof(HEADER)); memcpy(&pnode->m_rhdr,hdr,sizeof(HEADER)); if(pnode->r_allocate(hdr->total_length) == NULL) { *error = SRVR_ERR_MEMORY_ALLOCATE; IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); return; } memcpy(pnode->m_rbuffer, buffer, length); pnode->m_curptr = pnode->m_rbuffer + length; IOMessage_short_res_(message_tag, &call_id, exception_, *error, reply); break; case WRITE_REQUEST_NEXT: pnode = GTransport.m_FSystemSrvr_list->find_node(receiveInfo); if (pnode == NULL) { *error = SRVR_ERR_NODE_WRITE_REQUEST_NEXT; IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); return; } RESET_ERRORS((long)pnode); pnode->m_message_tag = message_tag; memset(&pnode->m_whdr,0,sizeof(HEADER)); memcpy(pnode->m_curptr, buffer, length); pnode->m_curptr += length; sts = IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); break; case READ_RESPONSE_FIRST: case READ_RESPONSE_NEXT: pnode = GTransport.m_FSystemSrvr_list->find_node(receiveInfo); if (pnode == NULL) { if (hdr->hdr_type == READ_RESPONSE_FIRST) *error = SRVR_ERR_NODE_READ_RESPONSE_FIRST; else *error = SRVR_ERR_NODE_READ_RESPONSE_NEXT; IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); return; } RESET_ERRORS((long)pnode); pnode->m_message_tag = message_tag; memset(&pnode->m_whdr,0,sizeof(HEADER)); if (hdr->hdr_type == READ_RESPONSE_FIRST) { memcpy(&call_id, &pnode->m_call_id, sizeof(CEE_handle_def)); pnode->m_max_reply_count = max_reply_count; if(pnode->m_trans_begin_tag != 0) RESUMETRANSACTION(pnode->m_trans_begin_tag); DISPATCH_IOMessage( (CEE_tag_def)pnode, &call_id, exception_, receiveInfo, dialogInfo, request, error, reply, hdr->operation_id ); length = pnode->m_reply_count; } else { length = pnode->m_curlength; buffer = pnode->m_curptr; if (length > max_reply_count) length = max_reply_count; reply->_length = length; reply->_buffer = (IDL_octet *)buffer; IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); } pnode->m_curlength -= length; pnode->m_curptr += length; if (pnode->m_curlength == 0) { if (pnode->m_rbuffer != NULL) { delete[] pnode->m_rbuffer; pnode->m_rbuffer = NULL; } if (pnode->m_wbuffer != NULL) { delete[] pnode->m_wbuffer; pnode->m_wbuffer = NULL; } DEALLOCATE_TEMP_MEMORY(&call_id); } break; case CLEANUP: GTransport.m_FSystemSrvr_list->cleanup_node(receiveInfo); IOMessage_short_res_( message_tag, &call_id, exception_, *error, reply); break; } }
CFSystemSrvr::~CFSystemSrvr() { RESET_ERRORS((long)this); cleanup(); }
int WRITE_TCPIP_RESPONSE(CTCPIPSystemSrvr* pnode, unsigned long message_length) { SRVRTRACE_ENTER(FILE_TSS+16); HEADER* hdr; char* buffer; int length; unsigned long total_length; total_length = message_length; short retcode = 0; short tx_handle[10]; memset(&tx_handle[0],0,20); retcode = GETTRANSID(&tx_handle[0]); if (retcode == 0) pnode->m_trans_begin_tag = tx_handle[0]; else pnode->m_trans_begin_tag = 0; if(GTransport.m_error_list.m_list_length) RESET_ERRORS((long)pnode); buffer = pnode->m_wbuffer; hdr = (HEADER*)pnode->m_wbuffer; memcpy(hdr, &pnode->m_rhdr, sizeof(HEADER)); hdr->total_length = message_length - sizeof(HEADER); if (hdr->compress_ind == COMP_YES && hdr->total_length > MIN_LENGTH_FOR_COMPRESSION) { total_length -= sizeof(HEADER); DoCompression(pnode, hdr, (unsigned char*)(buffer+sizeof(HEADER)), (unsigned long&)total_length); total_length += sizeof(HEADER); } else hdr->compress_type = COMP_NO_COMPRESSION; memcpy(&pnode->m_whdr, hdr, sizeof(HEADER)); if (hdr->swap == SWAP_YES) HEADER_swap(hdr); while (total_length > 0) { if (total_length > MAX_TCP_BUFFER_LENGTH) length = MAX_TCP_BUFFER_LENGTH; else length = total_length; if (pnode->do_write(buffer, length, pnode->m_whdr.operation_id, WRITE_TIMEOUT)== false) { // if there is error writing to a socket, makes no sense trying to write an error response to the socket // (if there is a send error, we'll actually cleanup the tcp/ip session, so there is no pnode either) SRVRTRACE_EXIT(FILE_TSS+16); return 1; } total_length -= length; buffer += length; } SRVRTRACE_EXIT(FILE_TSS+16); return 0; }
bool READ_TCPIP_REQUEST(CTCPIPSystemSrvr* pnode) { SRVRTRACE_ENTER(FILE_TSS+15); HEADER* hdr; HEADER swappedHdr; char* buffer; int length; unsigned long total_length; if(GTransport.m_error_list.m_list_length) RESET_ERRORS((long)pnode); length = pnode->m_rlength; if (pnode->do_read(true, hdr, buffer, length, READ_TIMEOUT)== false) { // if there is error writing to a socket, makes no sense trying to write an error response to the socket // (if there is a send error, we'll actually cleanup the tcp/ip session, so there is no pnode either) SRVRTRACE_EXIT(FILE_TSS+15); return false; } if (hdr->signature != SIGNATURE) { memcpy(&swappedHdr,hdr,sizeof(HEADER)); HEADER_swap(&swappedHdr); if(swappedHdr.signature != SIGNATURE) { pnode->send_error(SRVR_ERR_WRONG_MESSAGE_FORMAT, 0, NULL); SRVRTRACE_EXIT(FILE_TSS+15); return false; } else memcpy(&pnode->m_rhdr,&swappedHdr,sizeof(HEADER)); } else memcpy(&pnode->m_rhdr,hdr,sizeof(HEADER)); if(pnode->m_rhdr.operation_id == AS_API_GETOBJREF) { if(pnode->m_rhdr.version == CLIENT_HEADER_VERSION_LE) pnode->m_rhdr.swap = SWAP_NO; else if (pnode->m_rhdr.version == CLIENT_HEADER_VERSION_BE) pnode->m_rhdr.swap = SWAP_YES; else { // reject older clients pnode->send_error(SRVR_ERR_WRONG_MESSAGE_FORMAT, 0, NULL); SRVRTRACE_EXIT(FILE_TSS+15); return false; } pnode->m_rhdr.version = SERVER_HEADER_VERSION_LE; } hdr = &pnode->m_rhdr; if (pnode->m_rhdr.compress_ind == COMP_YES && pnode->m_rhdr.compress_type != COMP_NO_COMPRESSION) total_length = hdr->cmp_length; else total_length = hdr->total_length; if(pnode->r_allocate(total_length) == NULL) { pnode->send_error(SRVR_ERR_MEMORY_ALLOCATE,0, NULL); SRVRTRACE_EXIT(FILE_TSS+15); return false; } if (length < 0 || length > total_length) { pnode->send_error(SRVR_ERR_WRONG_MESSAGE_FORMAT,0, NULL); SRVRTRACE_EXIT(FILE_TSS+15); return false; } memcpy(pnode->m_rbuffer, buffer, length); pnode->m_curptr = pnode->m_rbuffer + length; total_length -= length; while(total_length > 0) { if (pnode->do_read(false, hdr, buffer, length, READ_TIMEOUT)== false) { // if there is error writing to a socket, makes no sense trying to write an error response to the socket // (if there is a send error, we'll actually cleanup the tcp/ip session, so there is no pnode either) SRVRTRACE_EXIT(FILE_TSS+15); return false; } if (length < 0 || length > total_length) { pnode->send_error(SRVR_ERR_WRONG_MESSAGE_FORMAT,0, NULL); SRVRTRACE_EXIT(FILE_TSS+15); return false; } memcpy(pnode->m_curptr, buffer, length); pnode->m_curptr += length; total_length -= length; } if (pnode->m_rhdr.compress_ind == COMP_YES && pnode->m_rhdr.compress_type != COMP_NO_COMPRESSION) { SRVRTRACE_EXIT(FILE_TSS+15); return DoExpand(pnode, pnode->m_rhdr, (unsigned char *)pnode->m_rbuffer, total_length); } SRVRTRACE_EXIT(FILE_TSS+15); return true; }
int CNSKListenerSrvr::runProgram(char* TcpProcessName, long port, int TransportTrace) { short fnum,error; _cc_status cc; short timeout; unsigned short countRead; SB_Tag_Type tag; sprintf(m_TcpProcessName,"%s",TcpProcessName); m_port = port; INITIALIZE_TRACE(TransportTrace); if ((error = FILE_OPEN_("$RECEIVE",8,&m_ReceiveFnum, 0, 0, 1, 4000)) != 0) { SET_ERROR((long)0, NSK, FILE_SYSTEM, UNKNOWN_API, E_SERVER, "runProgram", O_INIT_PROCESS, F_FILE_OPEN_, error, 0); return error; } if (ListenToPort(port) == false) return SRVR_ERR_LISTENER_ERROR1; READUPDATEX(m_ReceiveFnum, m_RequestBuf, MAX_BUFFER_LENGTH ); // Register with association server SRVR::RegisterSrvr(srvrGlobal->IpAddress, srvrGlobal->HostName); // Start tcpip listener thread tcpip_tid = tcpip_listener_thr.create("TCPIP_listener", CNSKListenerSrvr::tcpip_listener, this); // Persistently wait for input on $RECEIVE and then act on it. while(m_bKeepRunning) { RESET_ERRORS((long)0); timeout = -1; fnum = m_ReceiveFnum; cc = AWAITIOX(&fnum, OMITREF, &countRead, &tag, timeout); if (_status_lt(cc)) // some error or XCANCEL { //LCOV_EXCL_START error=0; XFILE_GETINFO_(fnum, &error); if (error == 26) // XCANCEL was called { //join the tcpip thread if(tcpip_tid != 0) tcpip_listener_thr.join(tcpip_tid,NULL); m_bKeepRunning = false; break; } //LCOV_EXCL_STOP } TRACE_INPUT(fnum,countRead,tag,cc); if (fnum == m_ReceiveFnum) { ADD_ONE_TO_HANDLE(&m_call_id); CheckReceiveMessage(cc, countRead, &m_call_id); READUPDATEX(m_ReceiveFnum, m_RequestBuf, MAX_BUFFER_LENGTH ); FS_TRACE_OUTPUT(cc); } else { //LCOV_EXCL_START TRACE_UNKNOWN_INPUT(); SET_ERROR((long)0, NSK, TCPIP, UNKNOWN_API, E_SERVER, "runProgram", O_DO_WRITE_READ, F_FILE_COMPLETE, SRVR_ERR_UNKNOWN_REQUEST, fnum); //LCOV_EXCL_STOP } } return 0; }
bool DoIO (CTCPIPUnixDrvr* pTCPIPSystem, IDL_char* wbuffer, IDL_long write_count, IDL_char*& rbuffer, IDL_long& read_count,CConnect *pConnection, CStmt *pStatement) { bool bok = true; // write count, read count and temporary count long wcount; long rcount = 0; int tcount = 0; char* buffer; rbuffer = NULL; // should the header specify swap #ifdef BIGE HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_BE,PC,TCPIP,SWAP_NO,0,0}; HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_BE,PC,TCPIP,SWAP_NO,0,0}; #else HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0}; HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0}; #endif HEADER* prheader,*pwheader; if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF) { ; } else { if(pTCPIPSystem->swap() == SWAP_YES) { wheader.swap = SWAP_YES; rheader.swap = SWAP_YES; } else { wheader.swap = SWAP_NO; rheader.swap = SWAP_NO; } } wheader.operation_id = pTCPIPSystem->odbcAPI; rheader.operation_id = pTCPIPSystem->odbcAPI; wheader.dialogueId = pTCPIPSystem->dialogueId; rheader.dialogueId = pTCPIPSystem->dialogueId; unsigned int timeout = pTCPIPSystem->dwTimeout; memset(&pTCPIPSystem->m_rheader, 0, sizeof(HEADER)); RESET_ERRORS((long)pTCPIPSystem); if (pTCPIPSystem->m_IOCompression > 0 && pTCPIPSystem->m_IOCompression == 1) { wheader.compress_ind = COMP_YES; //wheader.compress_type = COMP_14; // this should be set in the ::Compress method, based on what compression type the application chooses (right now there is only one COMP_14 rheader.compress_ind = COMP_YES; rheader.compress_type = COMP_14; // the driver requests that the server use this compression type. this should also be set based on what compression type the application chooses } else { wheader.compress_ind = COMP_NO; wheader.compress_type = 0; rheader.compress_ind = COMP_NO; rheader.compress_type = 0; } // send to the server wheader.total_length = write_count; wheader.hdr_type = WRITE_REQUEST_FIRST; wheader.compress_type = 0; #ifdef TRACE_COMPRESSION if(gDrvrGlobal.gTraceCompression) { printf("sending bytes number: %d\n",write_count); } #endif wcount = write_count; while (wcount > 0) { if (wheader.hdr_type == WRITE_REQUEST_FIRST) { if (wcount > MAX_TCP_BUFFER_LENGTH - sizeof(HEADER)) tcount = MAX_TCP_BUFFER_LENGTH - sizeof(HEADER); else tcount = wcount; } else { if (wcount > MAX_TCP_BUFFER_LENGTH) tcount = MAX_TCP_BUFFER_LENGTH; else tcount = wcount; } pwheader = &wheader; bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, pwheader, wbuffer, tcount, timeout); if (bok == false) goto out; wheader.hdr_type = WRITE_REQUEST_NEXT; wcount -= tcount; wbuffer += tcount; } // receive from the server pTCPIPSystem->cleanup(); //release all temp memory // read for READ_RESPONSE_FIRST tcount = 0; rbuffer = NULL; rheader.hdr_type = READ_RESPONSE_FIRST; prheader = &rheader; bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout); if(bok == false && pConnection != NULL) { if(MAP_SRVR_ERRORS(pConnection) == TIMEOUT_EXCEPTION) { if( pTCPIPSystem->odbcAPI != AS_API_GETOBJREF && pTCPIPSystem->odbcAPI != AS_API_STOPSRVR && pTCPIPSystem->odbcAPI != SRVR_API_SQLCONNECT && pTCPIPSystem->odbcAPI != SRVR_API_SQLDISCONNECT) { odbcas_ASSvc_StopSrvr_exc_ stopSrvrException; stopSrvrException.exception_nr=SQL_ERROR; if(pStatement != NULL) pStatement->setDiagRec(DRIVER_ERROR, IDS_S1_T00, TIMEOUT_EXCEPTION, FORMAT_ERROR((long)pStatement->getSrvrTCPIPSystem())); pConnection->sendStopServer(&stopSrvrException); bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout); } } } if (bok == false) goto out; if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF) { if(prheader->version == SERVER_HEADER_VERSION_LE) // we're connected to a Seaquest system #if defined(BIGE) pTCPIPSystem->setSwap(SWAP_YES); #else pTCPIPSystem->setSwap(SWAP_NO); #endif else if(prheader->version == SERVER_HEADER_VERSION_BE) // we're connected to a older system #if defined(BIGE) pTCPIPSystem->setSwap(SWAP_NO); #else pTCPIPSystem->setSwap(SWAP_YES); #endif else
bool DoIO (CTCPIPSystemDrvr* pTCPIPSystem, char* wbuffer, long write_count, char*& rbuffer, long& read_count, CConnect *pConnection, CStmt *pStatement) { bool bok = true; // write count, read count and temporary count long wcount; long rcount = 0; long tcount = 0; char* buffer; rbuffer = NULL; // HEADER wheader = {0,0,0,0,'N',COMP_12,WRITE_REQUEST_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0}; HEADER rheader = {0,0,0,0,'N',COMP_12,READ_RESPONSE_FIRST,SIGNATURE,CLIENT_HEADER_VERSION_LE,PC,TCPIP,SWAP_YES,0,0}; HEADER* prheader,*pwheader; if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF) { // For GetObjRef, the header is always sent in BigEndian form since when establishing a new connection // we won't know the system type ; } else { if(pTCPIPSystem->swap() == SWAP_NO) { // We're connected from a Little Endian Client to a Little Endian Server wheader.swap = SWAP_NO; rheader.swap = SWAP_NO; } else { // We're connected from a Little Endian Client to a Big Endian Server ; } } wheader.operation_id = pTCPIPSystem->odbcAPI; rheader.operation_id = pTCPIPSystem->odbcAPI; wheader.dialogueId = pTCPIPSystem->dialogueId; rheader.dialogueId = pTCPIPSystem->dialogueId; unsigned int timeout = pTCPIPSystem->dwTimeout; memset(&pTCPIPSystem->m_rheader, 0, sizeof(HEADER)); RESET_ERRORS((long)pTCPIPSystem); if (pTCPIPSystem->m_IOCompression > 0 && pTCPIPSystem->m_IOCompression == 1) { wheader.compress_ind = COMP_YES; //wheader.compress_type = COMP_14; // this should be set in the ::Compress method, based on what compression type the application chooses (right now there is only one COMP_14 rheader.compress_ind = COMP_YES; rheader.compress_type = COMP_14; // the driver requests that the server use this compression type. this should also be set based on what compression type the application chooses } else { wheader.compress_ind = COMP_NO; wheader.compress_type = 0; rheader.compress_ind = COMP_NO; rheader.compress_type = 0; } // send to the server wheader.total_length = write_count; wheader.hdr_type = WRITE_REQUEST_FIRST; wheader.compress_type = 0; #if (defined(WIN32)||defined(_WIN64))&&defined(TRACE_COMPRESSION) if(gDrvrGlobal.gTraceCompression) { printf("sending bytes number: %d\n",write_count); } #endif wcount = write_count; while (wcount > 0) { if (wheader.hdr_type == WRITE_REQUEST_FIRST) { if (wcount > MAX_TCP_BUFFER_LENGTH - sizeof(HEADER)) tcount = MAX_TCP_BUFFER_LENGTH - sizeof(HEADER); else tcount = wcount; } else { if (wcount > MAX_TCP_BUFFER_LENGTH) tcount = MAX_TCP_BUFFER_LENGTH; else tcount = wcount; } pwheader = &wheader; TRACE_TRANSPORT_OUT(wheader.hdr_type, pTCPIPSystem->m_object_ref, pwheader, wbuffer, tcount, timeout); bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, pwheader, wbuffer, tcount, timeout); if (bok == false) goto out; wheader.hdr_type = WRITE_REQUEST_NEXT; wcount -= tcount; wbuffer += tcount; } // receive from the server pTCPIPSystem->cleanup(); //release all temp memory // read for READ_RESPONSE_FIRST tcount = 0; rbuffer = NULL; rheader.hdr_type = READ_RESPONSE_FIRST; prheader = &rheader; bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout); if(bok == false) { if(MAP_SRVR_ERRORS(pConnection) == TIMEOUT_EXCEPTION) { if( pTCPIPSystem->odbcAPI != AS_API_GETOBJREF && pTCPIPSystem->odbcAPI != AS_API_STOPSRVR && pTCPIPSystem->odbcAPI != SRVR_API_SQLCONNECT && pTCPIPSystem->odbcAPI != SRVR_API_SQLDISCONNECT) { if(pStatement != NULL) pStatement->setDiagRec(DRIVER_ERROR, IDS_S1_T00, TIMEOUT_EXCEPTION, FORMAT_ERROR((long)pStatement->getSrvrTCPIPSystem())); pConnection->sendStopServer(); bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout); } } } if (bok == false) goto out; TRACE_TRANSPORT_IN(READ_RESPONSE_FIRST, pTCPIPSystem->m_object_ref, prheader, rbuffer, tcount, timeout); if(pTCPIPSystem->odbcAPI == AS_API_GETOBJREF) { if(prheader->version == SERVER_HEADER_VERSION_LE) pTCPIPSystem->setSwap(SWAP_NO); else if(prheader->version == SERVER_HEADER_VERSION_BE) pTCPIPSystem->setSwap(SWAP_YES); else // we're connected to an older system (which will just echo back the version we send) pTCPIPSystem->setSwap(SWAP_YES); } // the server returns total length in the header memcpy(&pTCPIPSystem->m_rheader, prheader, sizeof(HEADER)); if (prheader->compress_ind == COMP_YES && prheader->compress_type != 0) { SET_ERROR((long)pTCPIPSystem, PC, TCPIP, pTCPIPSystem->odbcAPI, E_DRIVER, pTCPIPSystem->m_object_ref, O_DO_WRITE_READ, F_DO_IO, DRVR_ERR_COMPRESS_OPERATION, rcount); bok = false; goto out; } else rcount = prheader->total_length; read_count = rcount; buffer = (char*)pTCPIPSystem->r_allocate(rcount); if (buffer == NULL) { SET_ERROR((long)pTCPIPSystem, PC, TCPIP, pTCPIPSystem->odbcAPI, E_DRIVER, pTCPIPSystem->m_object_ref, O_DO_OPERATOR_NEW, F_DO_IO, DRVR_ERR_MEMORY_ALLOCATE, rcount); bok = false; goto out; } // if there is something beside the header in the IO buffer if (tcount > 0) { memcpy(buffer, rbuffer, tcount); rcount -= tcount; } rbuffer = buffer+ tcount; // read for READ_RESPONSE_NEXT while (rcount > 0){ // we send only a header tcount = 0; rheader.hdr_type = READ_RESPONSE_NEXT; prheader = &rheader; bok = (gDrvrGlobal.fpTCPIPDoWriteRead)((void*)pTCPIPSystem, prheader, rbuffer, tcount, timeout); if (bok == false) goto out; TRACE_TRANSPORT_IN(READ_RESPONSE_NEXT, pTCPIPSystem->m_object_ref, prheader, rbuffer, tcount, timeout); rcount -= tcount; rbuffer += tcount; } rbuffer = buffer; #if (defined(WIN32)||defined(_WIN64))&&defined(TRACE_COMPRESSION) if(gDrvrGlobal.gTraceCompression) { printf("receiving bytes number: %d\n",read_count); } #endif out: return bok; }