vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I believe I am supposed to use ct_con_props in order to check the connection status. My program looks like the following... // send command to the database if ( CS_FAIL == (nRetVal = ct_send(m_pCmd) ) ) { CS_INT status = CS_CONSTAT_DEAD; ct_con_props(m_pDatabase->pCnx, CS_GET, CS_CON_STATUS, NULL, 0, &status); if(status & CS_CONSTAT_DEAD) { // Broken connection... } } // make sure that send worked OK if (CS_FAIL == (nRetVal = ct_results( m_pCmd, &nRetVal2) ) ) { CS_INT status = CS_CONSTAT_DEAD; ct_con_props(m_pDatabase->pCnx, CS_GET, CS_CON_STATUS, NULL, 0, &status); if(status & CS_CONSTAT_DEAD) { // Broken connection... } } After I unplug the network cable, ct_results and ct_send return CS_FAIL as expected. However, the ct_con_props reset the status to 0, instead of indicating the connection is dead by setting the bitmap. Did I do anything wrong or was I missing something? Thanks for any help. Andy |
| |||
| Hello, Unplugging the network cable does not mean the connection is dead. If you plug it back in before certain TCP kernel parameters expire, the connection might still be useable. On Solaris, these parameters are: tcp_ip_abort_cinterval Abort timeout at connect time. This is the 3-way handshake abort timer. The default value is 180000 (3 MIN) tcp_ip_abort_interval Abort interval used after connected (abort timeout for an established connection) This is the maximum time TCP retransmits will be tried for a connection in the ESTABLISHED state should be tried before a RESET segment is sent. Default 480000 (8*MINUTES) So you would have to wait about 8 minutes before TCP told Sybase that the connection was dead. I would not suggest checking the CS_CON_STATUS after each command because there are plenty of other reasons for ct_send or ct_results to fail. Ideally, you would use set CS_TIMEOUT so that your command times out. Then in your error handler, you try to ct_cancel() the connection and possibly checking the connection property. |
| |||
| Thanks for your response. I'm checking the connection status because I need to differentiate this particular failure from the others. In my case, the ct_send already returns a failure after I unplug the network cable. I try plugging it back and call ct_send again, it still fail and it does seem like the connection is restored. Sound the connection property tell me the connection is dead? Or am I supposed to check connection status after ct_cancel as you mentioned? Thanks! Andy |
| |||
| I would check the connection status after trying to cancel it. I think I have a code sample somewhere but I am away from the office and won't have access to it for awhile. * A connection can become unusable due to error. If this occurs, Client-Library marks the connection as "dead." An application can use the CS_CON_STATUS property to determine if a connection has been marked "dead." If a connection has been marked "dead" because of a results-processing error, an application can try calling ct_cancel(CS_CANCEL_ALL or CS_CANCEL_ATTN) to revive the connection. If this fails, the application must close the connection and drop its CS_CONNECTION structure. |
| |||
| Thanks for you suggestion. I made some change to my code to something similar to the following. However, the ct_con_props still reset status to 0. Did I get you right? Thanks Andy if ( CS_FAIL == (nRetVal = ct_send(m_pCmd) ) ) { ct_cancel(NULL, m_pCmd, CS_CANCEL_ALL) ; CS_INT status = CS_CONSTAT_DEAD; ct_con_props(m_pDatabase->pCnx, CS_GET, CS_CON_STATUS, NULL, 0, &status); if(status & CS_CONSTAT_DEAD) { // connection failed! } } // make sure that send worked OK if (CS_FAIL == (nRetVal = ct_results( m_pCmd, &nRetVal2) ) ) { ct_cancel(NULL, m_pCmd, CS_CANCEL_ALL) ; CS_INT status = CS_CONSTAT_DEAD; ct_con_props(m_pDatabase->pCnx, CS_GET, CS_CON_STATUS, NULL, 0, &status); if(status & CS_CONSTAT_DEAD) { // connection failed! } } |
| Thread Tools | |
| Display Modes | |
|
|