Skip to content

Commit 3724ee3

Browse files
feat: Add C equivalent code in libccxr_exports & use in networking.c
1 parent 7b4a449 commit 3724ee3

File tree

2 files changed

+332
-0
lines changed

2 files changed

+332
-0
lines changed

src/lib_ccx/networking.c

+46
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ const char *srv_pwd;
4545
unsigned char *srv_header;
4646
size_t srv_header_len;
4747

48+
#ifndef DISABLE_RUST
49+
extern void ccxr_connect_to_srv(const char *addr, const char *port, const char *cc_desc, const char *pwd);
50+
extern void ccxr_net_send_header(const unsigned char *data, size_t len);
51+
extern int ccxr_net_send_cc(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);
52+
extern void ccxr_net_check_conn();
53+
extern void ccxr_net_send_epg(
54+
const char *start,
55+
const char *stop,
56+
const char *title,
57+
const char *desc,
58+
const char *lang,
59+
const char *category);
60+
extern int ccxr_net_tcp_read(int socket, void *buffer, size_t length);
61+
extern int ccxr_net_udp_read(int socket, void *buffer, size_t length, const char *src_str, const char *addr_str);
62+
extern int ccxr_start_tcp_srv(const char *port, const char *pwd);
63+
extern int ccxr_start_udp_srv(const char *src, const char *addr, unsigned port);
64+
#endif
65+
4866
/*
4967
* Established connection to specified address.
5068
* Returns socked id
@@ -84,6 +102,9 @@ int set_nonblocking(int fd);
84102

85103
void connect_to_srv(const char *addr, const char *port, const char *cc_desc, const char *pwd)
86104
{
105+
#ifndef DISABLE_RUST
106+
return ccxr_connect_to_srv(addr, port, cc_desc, pwd);
107+
#endif
87108
if (NULL == addr)
88109
{
89110
mprint("Server address is not set\n");
@@ -115,6 +136,9 @@ void connect_to_srv(const char *addr, const char *port, const char *cc_desc, con
115136

116137
void net_send_header(const unsigned char *data, size_t len)
117138
{
139+
#ifndef DISABLE_RUST
140+
return ccxr_net_send_header(data, len);
141+
#endif
118142
assert(srv_sd > 0);
119143

120144
#if DEBUG_OUT
@@ -141,6 +165,9 @@ void net_send_header(const unsigned char *data, size_t len)
141165

142166
int net_send_cc(const unsigned char *data, int len, void *private_data, struct cc_subtitle *sub)
143167
{
168+
#ifndef DISABLE_RUST
169+
return ccxr_net_send_cc(data, len, private_data, sub);
170+
#endif
144171
assert(srv_sd > 0);
145172

146173
#if DEBUG_OUT
@@ -160,6 +187,9 @@ int net_send_cc(const unsigned char *data, int len, void *private_data, struct c
160187

161188
void net_check_conn()
162189
{
190+
#ifndef DISABLE_RUST
191+
return ccxr_net_check_conn();
192+
#endif
163193
time_t now;
164194
static time_t last_ping = 0;
165195
char c = 0;
@@ -221,6 +251,9 @@ void net_send_epg(
221251
const char *lang,
222252
const char *category)
223253
{
254+
#ifndef DISABLE_RUST
255+
return ccxr_net_send_epg(start, stop, title, desc, lang, category);
256+
#endif
224257
size_t st;
225258
size_t sp;
226259
size_t t;
@@ -301,6 +334,9 @@ void net_send_epg(
301334

302335
int net_tcp_read(int socket, void *buffer, size_t length)
303336
{
337+
#ifndef DISABLE_RUST
338+
return ccxr_net_tcp_read(socket, buffer, length);
339+
#endif
304340
assert(buffer != NULL);
305341
assert(length > 0);
306342

@@ -333,6 +369,9 @@ int net_tcp_read(int socket, void *buffer, size_t length)
333369

334370
int net_udp_read(int socket, void *buffer, size_t length, const char *src_str, const char *addr_str)
335371
{
372+
#ifndef DISABLE_RUST
373+
return ccxr_net_udp_read(socket, buffer, length, src_str, addr_str);
374+
#endif
336375
assert(buffer != NULL);
337376
assert(length > 0);
338377

@@ -519,6 +558,9 @@ int tcp_connect(const char *host, const char *port)
519558

520559
int start_tcp_srv(const char *port, const char *pwd)
521560
{
561+
#ifndef DISABLE_RUST
562+
return ccxr_start_tcp_srv(port, pwd);
563+
#endif
522564
if (NULL == port)
523565
port = DFT_PORT;
524566

@@ -974,6 +1016,10 @@ ssize_t read_byte(int fd, char *ch)
9741016

9751017
int start_upd_srv(const char *src_str, const char *addr_str, unsigned port)
9761018
{
1019+
#ifndef DISABLE_RUST
1020+
return ccxr_start_udp_srv(src_str, addr_str, port);
1021+
#endif
1022+
9771023
init_sockets();
9781024

9791025
in_addr_t src;

0 commit comments

Comments
 (0)