Skip to content

Commit

Permalink
Added separated connect timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
di-shi committed Jul 19, 2024
1 parent d64bfa7 commit 3a6b670
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 6 deletions.
3 changes: 2 additions & 1 deletion RELNOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ Version 4.28.0 - 2024-07-08
* Enabled without token element.
* Fixed fcntl typo.

Version 4.29.0 - 2024-0x-xx
Version 4.29.0 - 2024-07-19
* Updated to support setting OSPC_DEFAULT_BLOCKING_FLAG.
* Added separated connect timeout.

3 changes: 3 additions & 0 deletions include/osp/ospcomm.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct {
unsigned HttpPersistence;
unsigned HttpRetryDelay;
unsigned HttpRetryLimit;
unsigned ConnectTimeout;
unsigned HttpTimeout;
OSPTUINT64 ConnSelectionTimeout;
OSPTSVCPT *ServicePointList;
Expand All @@ -98,10 +99,12 @@ extern "C" {
int OSPPCommGetPersistence(OSPTCOMM *, unsigned *);
int OSPPCommGetRetryDelay(OSPTCOMM *, unsigned *);
int OSPPCommGetRetryLimit(OSPTCOMM *, unsigned *);
int OSPPCommGetConnectTimeout(OSPTCOMM *, unsigned *);
int OSPPCommGetTimeout(OSPTCOMM *, unsigned *);
int OSPPCommSetPersistence(OSPTCOMM *, unsigned);
int OSPPCommSetRetryDelay(OSPTCOMM *, unsigned);
int OSPPCommSetRetryLimit(OSPTCOMM *, unsigned);
int OSPPCommSetConnectTimeout(OSPTCOMM *, unsigned);
int OSPPCommSetTimeout(OSPTCOMM *, unsigned);
int OSPPCommSetConnSelectionTimeout(OSPTCOMM *, OSPTUINT64);
int OSPPCommGetMaxConnections(OSPTCOMM *, unsigned *);
Expand Down
2 changes: 2 additions & 0 deletions include/osp/ospproviderapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
int OSPPProviderGetHTTPPersistence(OSPTPROVHANDLE, unsigned *);
int OSPPProviderGetHTTPRetryDelay(OSPTPROVHANDLE, unsigned *);
int OSPPProviderGetHTTPRetryLimit(OSPTPROVHANDLE, unsigned *);
int OSPPProviderGetConnectTimeout(OSPTPROVHANDLE, unsigned *);
int OSPPProviderGetHTTPTimeout(OSPTPROVHANDLE, unsigned *);
int OSPPProviderGetLocalKeys(OSPTPROVHANDLE, OSPTPRIVATEKEY *, unsigned, void *);
int OSPPProviderGetLocalValidation(OSPTPROVHANDLE, unsigned *);
Expand All @@ -47,6 +48,7 @@ extern "C" {
int OSPPProviderSetHTTPPersistence(OSPTPROVHANDLE, unsigned);
int OSPPProviderSetHTTPRetryDelay(OSPTPROVHANDLE, unsigned);
int OSPPProviderSetHTTPRetryLimit(OSPTPROVHANDLE, unsigned);
int OSPPProviderSetConnectTimeout(OSPTPROVHANDLE, unsigned);
int OSPPProviderSetHTTPTimeout(OSPTPROVHANDLE, unsigned);
int OSPPProviderSetLocalKeys(OSPTPROVHANDLE, const OSPTPRIVATEKEY *, const void *);
int OSPPProviderSetLocalValidation(OSPTPROVHANDLE, unsigned);
Expand Down
30 changes: 30 additions & 0 deletions src/ospcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,21 @@ int OSPPCommGetRetryLimit(
return errorcode;
}

int OSPPCommGetConnectTimeout(
OSPTCOMM *ospvComm,
unsigned *ospvTimeout)
{
int errorcode = OSPC_ERR_NO_ERROR;

if (ospvComm == OSPC_OSNULL) {
errorcode = OSPC_ERR_COMM_INVALID_ARG;
OSPM_DBGERRORLOG(errorcode, "ospvComm is NULL");
} else
*ospvTimeout = ospvComm->ConnectTimeout;

return errorcode;
}

int OSPPCommGetTimeout(
OSPTCOMM *ospvComm,
unsigned *ospvTimeout)
Expand Down Expand Up @@ -354,6 +369,21 @@ int OSPPCommSetConnSelectionTimeout(
return errorcode;
}

int OSPPCommSetConnectTimeout(
OSPTCOMM *ospvComm,
unsigned ospvTimeout)
{
int errorcode = OSPC_ERR_NO_ERROR;

if (ospvComm == OSPC_OSNULL) {
errorcode = OSPC_ERR_COMM_INVALID_ARG;
OSPM_DBGERRORLOG(errorcode, "ospvComm is NULL");
} else
ospvComm->ConnectTimeout = ospvTimeout;

return errorcode;
}

int OSPPCommSetTimeout(
OSPTCOMM *ospvComm,
unsigned ospvTimeout)
Expand Down
61 changes: 61 additions & 0 deletions src/ospproviderapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ int OSPPProviderGetHTTPRetryLimit(
return errorcode;
}

/*
* OSPPProviderGetConnectTimeout()
*
* Get time, in milliseconds, to wait for connecting to a provider
* HTTP connection.
*
* The OSPPProviderGetConnectTimeout function returns the timeout value
* that specifies how long to wait for connecting to HTTP connections
* with ospvProvider. The value, returned in the location pointed to by
* ospvConnectTimeout, is measured in milliseconds.
*
* Returns: OSPC_ERR_NO_ERROR if successful, OSPC_ERR_xxx otherwise.
*/
int OSPPProviderGetConnectTimeout(
OSPTPROVHANDLE ospvProvider, /* In - Provider handle */
unsigned *ospvConnectTimeout) /* Out - Ptr to result store */
{
OSPTPROVIDER *provider = OSPC_OSNULL;
int errorcode = OSPC_ERR_NO_ERROR;

provider = OSPPProviderGetContext(ospvProvider, &errorcode);
if (errorcode == OSPC_ERR_NO_ERROR) {
errorcode = OSPPCommGetConnectTimeout(provider->Comm, ospvConnectTimeout);
}

return errorcode;
}

/*
* OSPPProviderGetHTTPTimeout()
*
Expand Down Expand Up @@ -974,6 +1002,39 @@ int OSPPProviderSetHTTPRetryLimit(
return errorcode;
}

/*
* OSPPProviderSetConnectTimeout()
*
* Configure maximum time in ms to wait for connecting to provider.
*
* The OSPPProviderSetConnectTimeout function configures the maximum
* amount of time to wait for connecting to ospvProvider. That timeout,
* expressed in milliseconds, is indicated by the ospvConnectTimeout
* parameter. If no connection is established within this time, the current
* connection is aborted and the library attempts to connect with another
* service point.
*
* Returns: OSPC_ERR_NO_ERROR if successful, OSPC_ERR_xxx otherwise.
*/
int OSPPProviderSetConnectTimeout(
OSPTPROVHANDLE ospvProvider, /* In - Provider handle */
unsigned ospvConnectTimeout) /* In - New connect timeout */
{
OSPTPROVIDER *provider = OSPC_OSNULL;
int errorcode = OSPC_ERR_NO_ERROR;

provider = OSPPProviderGetContext(ospvProvider, &errorcode);
if (errorcode == OSPC_ERR_NO_ERROR) {
errorcode = OSPPCommSetConnectTimeout(provider->Comm, ospvConnectTimeout);
}

if (errorcode == OSPC_ERR_NO_ERROR) {
errorcode = OSPPCommSetConnectTimeout(provider->CommForCapabilities, ospvConnectTimeout);
}

return errorcode;
}

/*
* OSPPProviderSetHTTPTimeout()
*
Expand Down
14 changes: 10 additions & 4 deletions src/ospsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ int OSPPSockConnectAuditURL(
(ospvHttp->Flags & OSPC_SOCK_CONNECTED_MASK);

/*
* set the response timeout for the socket
* set the connect timeout for the socket
*/
OSPPCommGetTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
OSPPCommGetConnectTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
if (socktimeout == 0) {
OSPPCommGetTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
}

timeout.tv_sec = socktimeout / 1000;
timeout.tv_usec = socktimeout % 1000 * 1000;
Expand Down Expand Up @@ -323,9 +326,12 @@ int OSPPSockConnectServicePoint(
ospvHttp->Flags = (unsigned char)(ospvHttp->Flags & OSPC_SOCK_CONNECTED_MASK);

/*
* set the response timeout for the socket
* set the connect timeout for the socket
*/
OSPPCommGetTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
OSPPCommGetConnectTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
if (socktimeout == 0) {
OSPPCommGetTimeout((OSPTCOMM *)ospvHttp->Comm, &socktimeout);
}

timeout.tv_sec = socktimeout / 1000;
timeout.tv_usec = socktimeout % 1000 * 1000;
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ linux: $(TESTOBJS)

clean :
rm -f $(TESTAPP) $(TESTOBJS)
rm -f connect-test
30 changes: 29 additions & 1 deletion test/test_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#define DEF_HTTP_PERSIST 60000
#define DEF_HTTP_RETRYDELAY 0
#define DEF_HTTP_RETRYLIMIT 1
#define DEF_CONNECT_TIMEOUT (10 * 1000)
#define DEF_HTTP_TIMEOUT (60 * 1000)
#define DEF_TIME_LIMIT 4
#define DEF_CUST_ID 1000L
Expand Down Expand Up @@ -446,6 +447,26 @@ int testOSPPProviderSetHTTPRetryDelay()
return errcode;
}

int testOSPPProviderGetConnectTimeout()
{
int errcode = 0;
unsigned timeout;

errcode = OSPPProviderGetConnectTimeout(OSPVProviderHandle, &timeout);

printf("connect timeout = %u\n", timeout);
return errcode;
}

int testOSPPProviderSetConnectTimeout()
{
int errcode = 0;

errcode = OSPPProviderSetConnectTimeout(OSPVProviderHandle, DEF_CONNECT_TIMEOUT);

return errcode;
}

int testOSPPProviderGetHTTPTimeout()
{
int errcode = 0;
Expand Down Expand Up @@ -2805,6 +2826,12 @@ int testAPI(int apinumber)
case 48:
errcode = testSetDestinationCount();
break;
case 81:
errcode = testOSPPProviderGetConnectTimeout();
break;
case 82:
errcode = testOSPPProviderSetConnectTimeout();
break;
case 50:
errcode = testSetCallingNumber();
break;
Expand Down Expand Up @@ -3294,7 +3321,7 @@ int testMenu()
if (!quietmode) {
printf("\nSocket API functions\n");
printf("---------------------------------------------------------------------\n");
printf(" 0) SetBlockFlag\n");
printf(" 0) SetBlockingFlag\n");
printf("---------------------------------------------------------------------\n");
printf("Provider API functions\n");
printf("---------------------------------------------------------------------\n");
Expand Down Expand Up @@ -3328,6 +3355,7 @@ int testMenu()
printf("43) BuildUsageFromScratch(OGW) 44) BuildUsageFromScratch(TGW)\n");
printf("45) GetLookAheadInfoIfPresent 46) ModifyDeviceIdentifiers\n");
printf("47) ModifyDeviceIdentifiersAgain 48) SetDestinationCount\n");
printf("81) GetConnectTimeout 82) SetConnectTimeout\n");
printf("99) Sleep for 2 seconds\n");
printf("---------------------------------------------------------------------\n");
printf("Configuration Parameters\n");
Expand Down

0 comments on commit 3a6b670

Please sign in to comment.