Skip to content

Commit 9b50a02

Browse files
committed
Unified API endpoing adding function
1 parent 9a24adf commit 9b50a02

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed

examples/async-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int main(int argc, char* argv[])
194194
endpt.bUnix = args.bUnix;
195195
endpt.bTLS = args.bSSL;
196196

197-
if (XAPI_Connect(&api, &endpt) < 0)
197+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_CLIENT) < 0)
198198
{
199199
XAPI_Destroy(&api);
200200
return XSTDERR;

examples/async-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int main(int argc, char* argv[])
231231
#endif
232232
}
233233

234-
if (XAPI_Listen(&api, &endpt) < 0)
234+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
235235
{
236236
XAPI_Destroy(&api);
237237
return XSTDERR;

examples/http-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int main(int argc, char* argv[])
273273
#endif
274274
}
275275

276-
if (XAPI_Listen(&api, &endpt) < 0)
276+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
277277
{
278278
XAPI_Destroy(&api);
279279
return XSTDERR;

examples/ws-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int main(int argc, char* argv[])
271271
session_data_t sessData;
272272
endpt.pSessionData = &sessData;
273273

274-
if (XAPI_Connect(&api, &endpt) < 0)
274+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_CLIENT) < 0)
275275
{
276276
XAPI_Destroy(&api);
277277
return XSTDERR;

examples/ws-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ int main(int argc, char* argv[])
354354
#endif
355355
}
356356

357-
if (XAPI_Listen(&api, &endpt) < 0)
357+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
358358
{
359359
XAPI_Destroy(&api);
360360
return XSTDERR;

src/net/api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,3 +1324,15 @@ XSTATUS XAPI_Connect(xapi_t *pApi, xapi_endpoint_t *pEndpt)
13241324

13251325
return XSTDOK;
13261326
}
1327+
1328+
XSTATUS XAPI_AddEndpoint(xapi_t *pApi, xapi_endpoint_t *pEndpt, xapi_role_t eRole)
1329+
{
1330+
switch (eRole)
1331+
{
1332+
case XAPI_SERVER: return XAPI_Listen(pApi, pEndpt);
1333+
case XAPI_CLIENT: return XAPI_Connect(pApi, pEndpt);
1334+
default: break;
1335+
}
1336+
1337+
return XSTDERR;
1338+
}

src/net/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ XSTATUS XAPI_AuthorizeHTTP(xapi_data_t *pApiData, const char *pToken, const char
174174
void XAPI_InitEndpoint(xapi_endpoint_t *pEndpt);
175175
XSTATUS XAPI_Listen(xapi_t *pApi, xapi_endpoint_t *pEndpt);
176176
XSTATUS XAPI_Connect(xapi_t *pApi, xapi_endpoint_t *pEndpt);
177+
XSTATUS XAPI_AddEndpoint(xapi_t *pApi, xapi_endpoint_t *pEndpt, xapi_role_t eRole);
177178

178179
xevent_status_t XAPI_Service(xapi_t *pApi, int nTimeoutMs);
179180

tools/xtop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ int XTOPApp_ServerMode(xtop_args_t *pArgs, xtop_stats_t *pStats)
15671567
endpt.pAddr = pArgs->sAddr;
15681568
endpt.nPort = pArgs->nPort;
15691569

1570-
if (XAPI_Listen(&api, &endpt) < 0)
1570+
if (XAPI_AddEndpoint(&api, &endpt, XAPI_SERVER) < 0)
15711571
{
15721572
XAPI_Destroy(&api);
15731573
return XSTDERR;

0 commit comments

Comments
 (0)