Skip to content

Commit 1b5973e

Browse files
committed
server session NEW function for endpt existence checking
1 parent 4c770a0 commit 1b5973e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/session_server.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,29 @@ nc_server_endpt_count(void)
19831983
return server_opts.endpt_count;
19841984
}
19851985

1986+
API int
1987+
nc_server_is_endpt(const char *name)
1988+
{
1989+
uint16_t i;
1990+
int found = 0;
1991+
1992+
/* ENDPT READ LOCK */
1993+
pthread_rwlock_rdlock(&server_opts.endpt_lock);
1994+
1995+
/* check name uniqueness */
1996+
for (i = 0; i < server_opts.endpt_count; ++i) {
1997+
if (!strcmp(server_opts.endpts[i].name, name)) {
1998+
found = 1;
1999+
break;
2000+
}
2001+
}
2002+
2003+
/* ENDPT UNLOCK */
2004+
pthread_rwlock_unlock(&server_opts.endpt_lock);
2005+
2006+
return found;
2007+
}
2008+
19862009
int
19872010
nc_server_endpt_set_address_port(const char *endpt_name, const char *address, uint16_t port)
19882011
{

src/session_server.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ int nc_server_del_endpt(const char *name, NC_TRANSPORT_IMPL ti);
381381
*/
382382
int nc_server_endpt_count(void);
383383

384+
/**
385+
* @brief Check if an endpoint exists.
386+
*
387+
* @param[in] name Endpoint name.
388+
* @return 0 if does not exists, non-zero otherwise.
389+
*/
390+
int nc_server_is_endpt(const char *name);
391+
384392
/**
385393
* @brief Change endpoint listening address.
386394
*

0 commit comments

Comments
 (0)