Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add net module in lib_ccxr #1634

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/lib_ccx/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ const char *srv_pwd;
unsigned char *srv_header;
size_t srv_header_len;

#ifndef DISABLE_RUST
extern void ccxr_connect_to_srv(const char *addr, const char *port, const char *cc_desc, const char *pwd);
extern void ccxr_net_send_header(const unsigned char *data, size_t len);
extern int ccxr_net_send_cc(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);
extern void ccxr_net_check_conn();
extern void ccxr_net_send_epg(
const char *start,
const char *stop,
const char *title,
const char *desc,
const char *lang,
const char *category);
extern int ccxr_net_tcp_read(int socket, void *buffer, size_t length);
extern int ccxr_net_udp_read(int socket, void *buffer, size_t length, const char *src_str, const char *addr_str);
extern int ccxr_start_tcp_srv(const char *port, const char *pwd);
extern int ccxr_start_udp_srv(const char *src, const char *addr, unsigned port);
#endif

/*
* Established connection to specified address.
* Returns socked id
Expand Down Expand Up @@ -84,6 +102,9 @@ int set_nonblocking(int fd);

void connect_to_srv(const char *addr, const char *port, const char *cc_desc, const char *pwd)
{
#ifndef DISABLE_RUST
return ccxr_connect_to_srv(addr, port, cc_desc, pwd);
#endif
if (NULL == addr)
{
mprint("Server address is not set\n");
Expand Down Expand Up @@ -115,6 +136,9 @@ void connect_to_srv(const char *addr, const char *port, const char *cc_desc, con

void net_send_header(const unsigned char *data, size_t len)
{
#ifndef DISABLE_RUST
return ccxr_net_send_header(data, len);
#endif
assert(srv_sd > 0);

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

int net_send_cc(const unsigned char *data, int len, void *private_data, struct cc_subtitle *sub)
{
#ifndef DISABLE_RUST
return ccxr_net_send_cc(data, len, private_data, sub);
#endif
assert(srv_sd > 0);

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

void net_check_conn()
{
#ifndef DISABLE_RUST
return ccxr_net_check_conn();
#endif
time_t now;
static time_t last_ping = 0;
char c = 0;
Expand Down Expand Up @@ -221,6 +251,9 @@ void net_send_epg(
const char *lang,
const char *category)
{
#ifndef DISABLE_RUST
return ccxr_net_send_epg(start, stop, title, desc, lang, category);
#endif
size_t st;
size_t sp;
size_t t;
Expand Down Expand Up @@ -301,6 +334,9 @@ void net_send_epg(

int net_tcp_read(int socket, void *buffer, size_t length)
{
#ifndef DISABLE_RUST
return ccxr_net_tcp_read(socket, buffer, length);
#endif
assert(buffer != NULL);
assert(length > 0);

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

int net_udp_read(int socket, void *buffer, size_t length, const char *src_str, const char *addr_str)
{
#ifndef DISABLE_RUST
return ccxr_net_udp_read(socket, buffer, length, src_str, addr_str);
#endif
assert(buffer != NULL);
assert(length > 0);

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

int start_tcp_srv(const char *port, const char *pwd)
{
#ifndef DISABLE_RUST
return ccxr_start_tcp_srv(port, pwd);
#endif
if (NULL == port)
port = DFT_PORT;

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

int start_upd_srv(const char *src_str, const char *addr_str, unsigned port)
{
#ifndef DISABLE_RUST
return ccxr_start_udp_srv(src_str, addr_str, port);
#endif

init_sockets();

in_addr_t src;
Expand Down
Loading
Loading