Skip to content

Commit

Permalink
Unified API endpoing adding function
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Dec 25, 2024
1 parent 9a24adf commit 9b50a02
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/async-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char* argv[])
endpt.bUnix = args.bUnix;
endpt.bTLS = args.bSSL;

if (XAPI_Connect(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_CLIENT) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ int main(int argc, char* argv[])
#endif
}

if (XAPI_Listen(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down
2 changes: 1 addition & 1 deletion examples/http-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int main(int argc, char* argv[])
#endif
}

if (XAPI_Listen(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down
2 changes: 1 addition & 1 deletion examples/ws-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ int main(int argc, char* argv[])
session_data_t sessData;
endpt.pSessionData = &sessData;

if (XAPI_Connect(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_CLIENT) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down
2 changes: 1 addition & 1 deletion examples/ws-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ int main(int argc, char* argv[])
#endif
}

if (XAPI_Listen(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down
12 changes: 12 additions & 0 deletions src/net/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,3 +1324,15 @@ XSTATUS XAPI_Connect(xapi_t *pApi, xapi_endpoint_t *pEndpt)

return XSTDOK;
}

XSTATUS XAPI_AddEndpoint(xapi_t *pApi, xapi_endpoint_t *pEndpt, xapi_role_t eRole)
{
switch (eRole)
{
case XAPI_SERVER: return XAPI_Listen(pApi, pEndpt);
case XAPI_CLIENT: return XAPI_Connect(pApi, pEndpt);
default: break;
}

return XSTDERR;
}
1 change: 1 addition & 0 deletions src/net/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ XSTATUS XAPI_AuthorizeHTTP(xapi_data_t *pApiData, const char *pToken, const char
void XAPI_InitEndpoint(xapi_endpoint_t *pEndpt);
XSTATUS XAPI_Listen(xapi_t *pApi, xapi_endpoint_t *pEndpt);
XSTATUS XAPI_Connect(xapi_t *pApi, xapi_endpoint_t *pEndpt);
XSTATUS XAPI_AddEndpoint(xapi_t *pApi, xapi_endpoint_t *pEndpt, xapi_role_t eRole);

xevent_status_t XAPI_Service(xapi_t *pApi, int nTimeoutMs);

Expand Down
2 changes: 1 addition & 1 deletion tools/xtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ int XTOPApp_ServerMode(xtop_args_t *pArgs, xtop_stats_t *pStats)
endpt.pAddr = pArgs->sAddr;
endpt.nPort = pArgs->nPort;

if (XAPI_Listen(&api, &endpt) < 0)
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
{
XAPI_Destroy(&api);
return XSTDERR;
Expand Down

0 comments on commit 9b50a02

Please sign in to comment.