Skip to content

Commit

Permalink
[API] Dummy bonding API version if ENABLE_BONDING is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed May 4, 2022
1 parent 990b75a commit f82b131
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
18 changes: 6 additions & 12 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ typedef enum SRT_SOCKOPT {
SRTO_IPV6ONLY, // IPV6_V6ONLY mode
SRTO_PEERIDLETIMEO, // Peer-idle timeout (max time of silence heard from peer) in [ms]
SRTO_BINDTODEVICE, // Forward the SOL_SOCKET/SO_BINDTODEVICE option on socket (pass packets only from that device)
#if ENABLE_BONDING
SRTO_GROUPCONNECT, // Set on a listener to allow group connection
SRTO_GROUPMINSTABLETIMEO, // Minimum Link Stability timeout (backup mode) in milliseconds
SRTO_GROUPTYPE, // Group type to which an accepted socket is about to be added, available in the handshake
#endif
SRTO_GROUPCONNECT, // Set on a listener to allow group connection (ENABLE_BONDING)
SRTO_GROUPMINSTABLETIMEO, // Minimum Link Stability timeout (backup mode) in milliseconds (ENABLE_BONDING)
SRTO_GROUPTYPE, // Group type to which an accepted socket is about to be added, available in the handshake (ENABLE_BONDING)
SRTO_PACKETFILTER = 60, // Add and configure a packet filter
SRTO_RETRANSMITALGO = 61, // An option to select packet retransmission algorithm

Expand Down Expand Up @@ -942,14 +940,8 @@ SRT_API int64_t srt_connection_time(SRTSOCKET sock);

SRT_API int srt_clock_type(void);

#ifdef __cplusplus
}
#endif

// SRT Socket Groups API (ENABLE_BONDING)

#if ENABLE_BONDING

typedef enum SRT_GROUP_TYPE
{
SRT_GTYPE_UNDEFINED,
Expand Down Expand Up @@ -1007,6 +999,8 @@ SRT_API int srt_config_add(SRT_SOCKOPT_CONFIG* config, SRT_SOCKOPT option, const
SRT_API SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr* src /*nullable*/, const struct sockaddr* adr, int namelen);
SRT_API int srt_connect_group(SRTSOCKET group, SRT_SOCKGROUPCONFIG name[], int arraysize);

#endif // ENABLE_BONDING
#ifdef __cplusplus
}
#endif

#endif
64 changes: 43 additions & 21 deletions srtcore/srt_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,7 @@ int srt_config_add(SRT_SOCKOPT_CONFIG* config, SRT_SOCKOPT option, const void* c

return 0;
}
#endif

// int srt_bind_multicast()

// Binding and connection management
int srt_bind(SRTSOCKET u, const struct sockaddr * name, int namelen) { return CUDT::bind(u, name, namelen); }
int srt_bind_acquire(SRTSOCKET u, UDPSOCKET udpsock) { return CUDT::bind(u, udpsock); }
int srt_listen(SRTSOCKET u, int backlog) { return CUDT::listen(u, backlog); }
SRTSOCKET srt_accept(SRTSOCKET u, struct sockaddr * addr, int * addrlen) { return CUDT::accept(u, addr, addrlen); }
SRTSOCKET srt_accept_bond(const SRTSOCKET lsns[], int lsize, int64_t msTimeOut) { return CUDT::accept_bond(lsns, lsize, msTimeOut); }
int srt_connect(SRTSOCKET u, const struct sockaddr * name, int namelen) { return CUDT::connect(u, name, namelen, SRT_SEQNO_NONE); }
int srt_connect_debug(SRTSOCKET u, const struct sockaddr * name, int namelen, int forced_isn) { return CUDT::connect(u, name, namelen, forced_isn); }
int srt_connect_bind(SRTSOCKET u,
const struct sockaddr* source,
const struct sockaddr* target, int target_len)
{
return CUDT::connect(u, source, target, target_len);
}

#if ENABLE_BONDING
SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr* src, const struct sockaddr* adr, int namelen)
{
SRT_SOCKGROUPCONFIG data;
Expand All @@ -104,18 +85,59 @@ SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr* src, const struc
memset(&data.srcaddr, 0, sizeof data.srcaddr);
// Still set the family according to the target address
data.srcaddr.ss_family = adr->sa_family;
}
}
memcpy(&data.peeraddr, adr, namelen);
return data;
}

int srt_connect_group(SRTSOCKET group,
SRT_SOCKGROUPCONFIG name [], int arraysize)
SRT_SOCKGROUPCONFIG name[], int arraysize)
{
return CUDT::connectLinks(group, name, arraysize);
}

#else

SRTSOCKET srt_create_group(SRT_GROUP_TYPE) { return SRT_INVALID_SOCK; }
SRTSOCKET srt_groupof(SRTSOCKET) { return SRT_INVALID_SOCK; }
int srt_group_data(SRTSOCKET, SRT_SOCKGROUPDATA*, size_t*) { return srt::CUDT::APIError(MJ_NOTSUP, MN_INVAL, 0); }
int srt_group_configure(SRTSOCKET, const char*) { return srt::CUDT::APIError(MJ_NOTSUP, MN_INVAL, 0); }
SRT_SOCKOPT_CONFIG* srt_create_config() { return NULL; }
void srt_delete_config(SRT_SOCKOPT_CONFIG*) { return; }
int srt_config_add(SRT_SOCKOPT_CONFIG*, SRT_SOCKOPT, const void*, int) { return srt::CUDT::APIError(MJ_NOTSUP, MN_INVAL, 0); }

SRT_SOCKGROUPCONFIG srt_prepare_endpoint(const struct sockaddr*, const struct sockaddr*, int)
{
SRT_SOCKGROUPCONFIG data;
data.errorcode = SRT_EINVOP;
data.id = -1;
data.token = -1;
data.weight = 0;
data.config = NULL;
return data;
}

int srt_connect_group(SRTSOCKET, SRT_SOCKGROUPCONFIG[], int) { return srt::CUDT::APIError(MJ_NOTSUP, MN_INVAL, 0); }

#endif

// int srt_bind_multicast()

// Binding and connection management
int srt_bind(SRTSOCKET u, const struct sockaddr * name, int namelen) { return CUDT::bind(u, name, namelen); }
int srt_bind_acquire(SRTSOCKET u, UDPSOCKET udpsock) { return CUDT::bind(u, udpsock); }
int srt_listen(SRTSOCKET u, int backlog) { return CUDT::listen(u, backlog); }
SRTSOCKET srt_accept(SRTSOCKET u, struct sockaddr * addr, int * addrlen) { return CUDT::accept(u, addr, addrlen); }
SRTSOCKET srt_accept_bond(const SRTSOCKET lsns[], int lsize, int64_t msTimeOut) { return CUDT::accept_bond(lsns, lsize, msTimeOut); }
int srt_connect(SRTSOCKET u, const struct sockaddr * name, int namelen) { return CUDT::connect(u, name, namelen, SRT_SEQNO_NONE); }
int srt_connect_debug(SRTSOCKET u, const struct sockaddr * name, int namelen, int forced_isn) { return CUDT::connect(u, name, namelen, forced_isn); }
int srt_connect_bind(SRTSOCKET u,
const struct sockaddr* source,
const struct sockaddr* target, int target_len)
{
return CUDT::connect(u, source, target, target_len);
}

int srt_rendezvous(SRTSOCKET u, const struct sockaddr* local_name, int local_namelen,
const struct sockaddr* remote_name, int remote_namelen)
{
Expand Down

0 comments on commit f82b131

Please sign in to comment.