Browse Source

refactor udp module

Signed-off-by: surenyi <surenyi@gmail.com>
master
surenyi 9 years ago
parent
commit
6deb6ac1e2
  1. 13
      char_conv.c
  2. 15
      class/udp.c
  3. 24
      codec.c
  4. 31
      lan.c
  5. 4
      makefile
  6. 49
      udp.c
  7. 27
      udp.h
  8. 3
      udp_readable.c
  9. 1
      udp_readable.h
  10. 13
      wan.c

13
char_conv.c

@ -289,7 +289,7 @@ static void __is_readable(udp_readable_t *ur)
return; return;
} }
if ((len = ur->udp->recv(ur->udp, &tbabuf->bj, sizeof(tbabuf->bj))) <= 0) { if ((len = udp_recv(ur->udp, &tbabuf->bj, sizeof(tbabuf->bj))) <= 0) {
log_printf("recv baojin error!\n"); log_printf("recv baojin error!\n");
free(tbabuf); free(tbabuf);
return; return;
@ -370,7 +370,7 @@ static void __on_alarm(struct wan_alarm_handler *self, struct WanAlarmType *wat)
buf[idx++] = (cs >> 16) & 0xff; buf[idx++] = (cs >> 16) & 0xff;
buf[idx++] = (cs >> 24) & 0xff; buf[idx++] = (cs >> 24) & 0xff;
_udp->send(_udp, buf, idx); udp_send(_udp, buf, idx);
memcpy(&cv->wat, wat, sizeof *wat); memcpy(&cv->wat, wat, sizeof *wat);
} }
@ -385,14 +385,14 @@ char_conv_t *char_conv_new(int to_port, int from_port)
return NULL; return NULL;
} }
if (u->bind(u, LOIFADDR, from_port) < 0) { if (udp_bind(u, LOIFADDR, from_port) < 0) {
log_printf("'%s[%d]: can't bind [%s:%d] socket (%d: %s)\n", __FILE__, __LINE__, LOIFADDR, from_port, errno, strerror(errno)); log_printf("'%s[%d]: can't bind [%s:%d] socket (%d: %s)\n", __FILE__, __LINE__, LOIFADDR, from_port, errno, strerror(errno));
u->close(u); udp_close(u);
return NULL; return NULL;
} }
if (u->connect(u, LOIFADDR, to_port) < 0) { if (udp_connect(u, LOIFADDR, to_port) < 0) {
log_printf("'%s[%d]: can't connect [%s:%d] socket\n", __FILE__, __LINE__, LOIFADDR, to_port); log_printf("'%s[%d]: can't connect [%s:%d] socket\n", __FILE__, __LINE__, LOIFADDR, to_port);
u->close(u); udp_close(u);
return NULL; return NULL;
} }
@ -424,4 +424,3 @@ void char_conv_free(char_conv_t *cv)
iconv_close(cv->cd); iconv_close(cv->cd);
udp_readable_close(&cv->base); udp_readable_close(&cv->base);
} }

15
class/udp.c

@ -23,7 +23,7 @@ static void __is_readable(udp_readable_t *ur)
log_printf("lua udp no callback: %d\n", udp->uread); log_printf("lua udp no callback: %d\n", udp->uread);
return; return;
} }
if ((len = ur->udp->recv(ur->udp, buf, sizeof buf)) > 0) { if ((len = udp_recv(ur->udp, buf, sizeof buf)) > 0) {
lua_rawgeti(udp->uls, LUA_REGISTRYINDEX, udp->uread); lua_rawgeti(udp->uls, LUA_REGISTRYINDEX, udp->uread);
lua_pushlstring(udp->uls, buf,len); lua_pushlstring(udp->uls, buf,len);
lua_pcall(udp->uls, 1, 0, 0); lua_pcall(udp->uls, 1, 0, 0);
@ -118,7 +118,7 @@ int sock_udp_connect(lua_State *L)
p = luaL_checkinteger(L, 3); p = luaL_checkinteger(L, 3);
u = udp->base.udp; u = udp->base.udp;
p = u->connect(u, remote, p); p = udp_connect(u, remote, p);
lua_pushinteger(L,p); lua_pushinteger(L,p);
return 1; return 1;
} }
@ -133,7 +133,7 @@ int sock_udp_recv(lua_State *L)
udp = luaL_checkudata(L, 1, UDP_MT); udp = luaL_checkudata(L, 1, UDP_MT);
u = udp->base.udp; u = udp->base.udp;
n = u->recv(u, buf, sizeof buf); n = udp_recv(u, buf, sizeof buf);
if (n < 0) if (n < 0)
n = 0; n = 0;
lua_pushlstring(L, buf, n); lua_pushlstring(L, buf, n);
@ -152,7 +152,7 @@ int sock_udp_send(lua_State *L)
buf = lua_tolstring(L, 2, &len); buf = lua_tolstring(L, 2, &len);
u = udp->base.udp; u = udp->base.udp;
if (len > 0) if (len > 0)
n = u->send(u, (void *)buf, len); n = udp_send(u, (void *)buf, len);
lua_pushinteger(L, n); lua_pushinteger(L, n);
return 1; return 1;
} }
@ -167,8 +167,8 @@ static int sock_udp_bind(lua_State *L)
udp = luaL_checkudata(L, 1, UDP_MT); udp = luaL_checkudata(L, 1, UDP_MT);
addr = lua_tostring(L, 2); addr = lua_tostring(L, 2);
p = luaL_checkinteger(L, 3); p = luaL_checkinteger(L, 3);
u = udp->base.udp; u = udp->base.udp;
p = u->bind(u, addr, p); p = udp_bind(u, addr, p);
lua_pushinteger(L, p); lua_pushinteger(L, p);
return 1; return 1;
@ -185,7 +185,7 @@ static int sock_udp_close(lua_State *L)
luaL_unref(L, LUA_REGISTRYINDEX, udp->uread); luaL_unref(L, LUA_REGISTRYINDEX, udp->uread);
udp_readable_end(&udp->base); udp_readable_end(&udp->base);
} }
u->close(u); udp_close(u);
return 0; return 0;
} }
@ -226,4 +226,3 @@ int init_udp_class(lua_State *L)
return lua_add_class(L, "Udp", udp_class, UDP_MT, mt_udp_class); return lua_add_class(L, "Udp", udp_class, UDP_MT, mt_udp_class);
} }

24
codec.c

@ -156,7 +156,7 @@ static void up_tout_handler(struct timer *t)
sizeof cc->_encBuf - 2); sizeof cc->_encBuf - 2);
cc->_encBuf.id5 = 0x14; cc->_encBuf.id5 = 0x14;
u->send(u, &cc->_encBuf, sizeof cc->_encBuf); udp_send(u, &cc->_encBuf, sizeof cc->_encBuf);
} else { } else {
log_printf("BUG>> Upstream tout scheduled for NULL\n"); log_printf("BUG>> Upstream tout scheduled for NULL\n");
} }
@ -235,7 +235,7 @@ static void __on_up_audio( struct lan_audio_handler *lh,
cc->_encBuf.checkNum = getcs((uint8_t *)&cc->_encBuf, \ cc->_encBuf.checkNum = getcs((uint8_t *)&cc->_encBuf, \
sizeof cc->_encBuf - 2); sizeof cc->_encBuf - 2);
cc->_encBuf.id5 = 0x14; cc->_encBuf.id5 = 0x14;
u->send(u, &cc->_encBuf, sizeof cc->_encBuf); udp_send(u, &cc->_encBuf, sizeof cc->_encBuf);
/* after */ /* after */
upbuf->cbuf.len = 0; upbuf->cbuf.len = 0;
@ -286,7 +286,7 @@ static void __on_down_audio(struct wan_audio_handler *wh, struct WanAudioType *w
dump_bytes((uint8_t *)&cc->_decBuf, n); dump_bytes((uint8_t *)&cc->_decBuf, n);
} }
#else #else
u->send(u, (uint8_t *)&cc->_decBuf, sizeof cc->_decBuf); udp_send(u, (uint8_t *)&cc->_decBuf, sizeof cc->_decBuf);
#endif #endif
} }
@ -297,14 +297,14 @@ static udp_t *__make_link(const char *bridge_ip, int bridge_port, const char *lo
log_printf("'%s[%d]: can't create socket\n", __FILE__, __LINE__); log_printf("'%s[%d]: can't create socket\n", __FILE__, __LINE__);
return NULL; return NULL;
} }
if (_u->bind(_u, local_ip, local_port) < 0) { if (udp_bind(_u, local_ip, local_port) < 0) {
log_printf("'%s[%d]: can't bind [%s:%d] socket (%d: %s)\n", __FILE__, __LINE__, local_ip, local_port, errno, strerror(errno)); log_printf("'%s[%d]: can't bind [%s:%d] socket (%d: %s)\n", __FILE__, __LINE__, local_ip, local_port, errno, strerror(errno));
_u->close(_u); udp_close(_u);
return NULL; return NULL;
} }
if (_u->connect(_u, bridge_ip, bridge_port) < 0) { if (udp_connect(_u, bridge_ip, bridge_port) < 0) {
log_printf("'%s[%d]: can't connect [%s:%d] socket\n", __FILE__, __LINE__, local_ip, local_port); log_printf("'%s[%d]: can't connect [%s:%d] socket\n", __FILE__, __LINE__, local_ip, local_port);
_u->close(_u); udp_close(_u);
return NULL; return NULL;
} }
return _u; return _u;
@ -320,7 +320,7 @@ static void __up_readable(udp_readable_t *ur)
struct codec_complete *ccp = cc->_up_complete; struct codec_complete *ccp = cc->_up_complete;
/* send to uplink */ /* send to uplink */
if ((n = u->recv(u, buf, sizeof buf)) > 0) { if ((n = udp_recv(u, buf, sizeof buf)) > 0) {
ccp->on_complete(ccp, NULL, buf, n); ccp->on_complete(ccp, NULL, buf, n);
} }
} }
@ -424,7 +424,7 @@ static void __down_readable(udp_readable_t *ur)
uint8_t lanid; uint8_t lanid;
/* send to uplink */ /* send to uplink */
if ((n = u->recv(u, buf, sizeof(buf))) <= 0) if ((n = udp_recv(u, buf, sizeof(buf))) <= 0)
return; return;
if (n != sizeof(struct AudioEncType)) { if (n != sizeof(struct AudioEncType)) {
@ -485,7 +485,7 @@ void codec_self_test(codec_t *cc, udp_t *u)
}; };
(void)cc; (void)cc;
buf[8] = getcs(buf, 8); buf[8] = getcs(buf, 8);
u->send(u, buf, sizeof buf); udp_send(u, buf, sizeof buf);
}; };
codec_t *codec_new(const char *bridge_ip, int bridge_port, const char *local_ip, int down_port, int up_port) codec_t *codec_new(const char *bridge_ip, int bridge_port, const char *local_ip, int down_port, int up_port)
@ -499,7 +499,7 @@ codec_t *codec_new(const char *bridge_ip, int bridge_port, const char *local_ip,
} }
if (( u = __make_link( bridge_ip, bridge_port, local_ip, up_port)) == NULL) { if (( u = __make_link( bridge_ip, bridge_port, local_ip, up_port)) == NULL) {
d->close(d); udp_close(d);
return NULL; return NULL;
} }
cc = calloc(1, sizeof *cc); cc = calloc(1, sizeof *cc);
@ -563,5 +563,3 @@ void codec_free(codec_t *cc)
udp_readable_close(&uw->base); udp_readable_close(&uw->base);
free(cc); free(cc);
} }

31
lan.c

@ -1,4 +1,5 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
@ -62,7 +63,7 @@ static void __mcast_readable(udp_readable_t *ur)
udp_t *u = ur->udp; udp_t *u = ur->udp;
/* 16 bytes header + 160 bytes playload */ /* 16 bytes header + 160 bytes playload */
if ((len = u->recv(u, buf, sizeof buf)) != 176) if ((len = udp_recv(u, buf, sizeof buf)) != 176)
return; return;
//log_printf("lan recv audio packet %d bytes\n", len); //log_printf("lan recv audio packet %d bytes\n", len);
if (buf[0] == MSG_TYPE_AUDIO) if (buf[0] == MSG_TYPE_AUDIO)
@ -130,7 +131,7 @@ static void __on_downlink(struct codec_complete *cc, void *msgType, uint8_t *buf
len = sizeof msg - sizeof *ma; len = sizeof msg - sizeof *ma;
ma->payloadLen = htonl(len); ma->payloadLen = htonl(len);
memcpy(ma->payload, buf, len); memcpy(ma->payload, buf, len);
u->send(u, msg, sizeof msg); udp_send(u, msg, sizeof msg);
} }
static void __do_cmd(lan_t *ln, udp_t *u, uint8_t *buf, int len) static void __do_cmd(lan_t *ln, udp_t *u, uint8_t *buf, int len)
@ -154,7 +155,7 @@ static void __do_cmd(lan_t *ln, udp_t *u, uint8_t *buf, int len)
#ifdef DEBUG_LAN #ifdef DEBUG_LAN
dump_bytes((uint8_t *)&hdr, 12); dump_bytes((uint8_t *)&hdr, 12);
#endif #endif
u->send(u, &hdr, sizeof hdr); udp_send(u, &hdr, sizeof hdr);
len -= sizeof hdr; len -= sizeof hdr;
buf += sizeof hdr; buf += sizeof hdr;
/* 6 x 4 bytes: /* 6 x 4 bytes:
@ -195,7 +196,7 @@ static void __is_readable(udp_readable_t *ur)
#ifdef DEBUG_LAN #ifdef DEBUG_LAN
log_printf("lan reading\n"); log_printf("lan reading\n");
#endif #endif
if ((len = _u->recv(_u, buf, sizeof buf)) < LAN_PKT_MIN_LEN) { if ((len = udp_recv(_u, buf, sizeof buf)) < LAN_PKT_MIN_LEN) {
return; return;
} }
#ifdef DEBUG_LAN #ifdef DEBUG_LAN
@ -253,7 +254,7 @@ static int __on_alarm_data(struct alarm_data_handler *self, struct WanAlarmType
buf[n++] = 160; buf[n++] = 160;
memcpy(buf+16, bufin, len); memcpy(buf+16, bufin, len);
return u->send(u, buf, sizeof(buf)); return udp_send(u, buf, sizeof(buf));
} }
static void __on_alarming(struct alarm_data_handler *self, struct WanAlarmType *wat, int on) static void __on_alarming(struct alarm_data_handler *self, struct WanAlarmType *wat, int on)
@ -280,7 +281,7 @@ static void __on_alarming(struct alarm_data_handler *self, struct WanAlarmType *
buf[n++] = (sn >> 16) & 0xff; buf[n++] = (sn >> 16) & 0xff;
buf[n++] = (sn >> 8) & 0xff; buf[n++] = (sn >> 8) & 0xff;
buf[n++] = sn & 0xff; buf[n++] = sn & 0xff;
u->send(u, buf, n); udp_send(u, buf, n);
} }
int lan_ptt_response(lan_t *ln, int resp_type, struct MsgCmd *hdr, int status) int lan_ptt_response(lan_t *ln, int resp_type, struct MsgCmd *hdr, int status)
@ -303,7 +304,7 @@ int lan_ptt_response(lan_t *ln, int resp_type, struct MsgCmd *hdr, int status)
pkt.msgCmd = htons(MSG_RES_PTTOFF); pkt.msgCmd = htons(MSG_RES_PTTOFF);
break; break;
} }
u->send(u, &pkt, sizeof pkt); udp_send(u, &pkt, sizeof pkt);
return 0; return 0;
} }
@ -318,20 +319,21 @@ lan_t *lan_new(const char *dest_addr, int port, const char *local_if)
return NULL; return NULL;
} }
log_printf("local: %s, %s, %d\n", local_if, dest_addr, port); log_printf("local: %s, %s, %d\n", local_if, dest_addr, port);
if (u->bind(u, local_if, port) < 0) { if (udp_bind(u, local_if, port) < 0) {
log_printf("'%s[%d]: can't bind Lan socket\n", __func__, __LINE__); log_printf("'%s[%d]: bind lan socket(%s:%d), errno %d: %s.\n", __func__, __LINE__, local_if, port,
u->close(u); errno, strerror(errno));
udp_close(u);
return NULL; return NULL;
} }
if (u->connect(u, dest_addr, port) < 0) { if (udp_connect(u, dest_addr, port) < 0) {
log_printf("'%s[%d]: can't connect Lan socket\n", __func__, __LINE__); log_printf("'%s[%d]: can't connect Lan socket\n", __func__, __LINE__);
u->close(u); udp_close(u);
return NULL; return NULL;
} }
ln = (lan_t *)udp_readable_open(sizeof *ln, u); ln = (lan_t *)udp_readable_open(sizeof *ln, u);
if (ln == NULL) { if (ln == NULL) {
u->close(u); udp_close(u);
return NULL; return NULL;
} }
ln->base.is_readable = __is_readable; ln->base.is_readable = __is_readable;
@ -352,7 +354,6 @@ void lan_free(lan_t *ln)
#ifdef LAN_RECORD #ifdef LAN_RECORD
udp_readable_end(&ln->audioSock.base); udp_readable_end(&ln->audioSock.base);
#endif #endif
u->close(u); udp_close(u);
udp_readable_close(&ln->base); udp_readable_close(&ln->base);
} }

4
makefile

@ -5,8 +5,8 @@ CC := cc
INCLUDE := $(TARGET_ROOT)/include INCLUDE := $(TARGET_ROOT)/include
LIBDIR := $(TARGET_ROOT)/lib LIBDIR := $(TARGET_ROOT)/lib
DEBUG := -g -ggdb -Werror #DEBUG := -g -ggdb -Werror
#DEBUG := -O2 -s DEBUG := -O2 -s
CFLAGS += -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing \ CFLAGS += -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing \
-I$(PWD) -I$(PWD)/class -I$(INCLUDE) -I$(INCLUDE)/luajit-2.0 -Wall -Wextra \ -I$(PWD) -I$(PWD)/class -I$(INCLUDE) -I$(INCLUDE)/luajit-2.0 -Wall -Wextra \
$(DEBUG) $(DEBUG)

49
udp.c

@ -81,33 +81,37 @@ udp_t *udp_open()
{ {
int s; int s;
udp_t *u; udp_t *u;
static struct udpops uops = {
.bind = __bind,
.connect = __connect,
.send = __send,
.recv = __recv,
.close =__close
};
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return NULL; return NULL;
set_sock_attributes(s); set_sock_attributes(s);
u = calloc(1, sizeof *u); u = calloc(1, sizeof *u);
u->uops = &uops;
u->sock = s; u->sock = s;
u->bind = __bind;
u->connect = __connect;
u->send = __send;
u->recv = __recv;
u->close = __close;
return u; return u;
} }
static struct udp_multicast * __mcast_new(const char *grp_addr, int port, int s) static struct udp_multicast * __mcast_new(const char *grp_addr, int port, int s)
{ {
struct udp_multicast *u; struct udp_multicast *u;
static struct udpops uops = {
.bind = __bind,
.connect = __connect,
.send = __send2,
.recv = __recv,
.close = __close
};
u = calloc(1, sizeof *u); u = calloc(1, sizeof *u);
u->base.uops = &uops;
u->base.sock = s; u->base.sock = s;
u->base.bind = __bind;
u->base.connect = __connect;
u->base.send = __send2;
u->base.recv = __recv;
u->base.close = __close;
u->dest_addr.sin_family = AF_INET; u->dest_addr.sin_family = AF_INET;
u->dest_addr.sin_port = htons(port); u->dest_addr.sin_port = htons(port);
u->dest_addr.sin_addr.s_addr = inet_addr(grp_addr); u->dest_addr.sin_addr.s_addr = inet_addr(grp_addr);
@ -120,6 +124,7 @@ udp_t * udp_open_mcast(const char *grp_addr, int port, const char *local)
struct ip_mreq group; struct ip_mreq group;
struct in_addr ethx; struct in_addr ethx;
int sock; int sock;
udp_t *u;
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) { if (sock < 0) {
@ -155,13 +160,10 @@ udp_t * udp_open_mcast(const char *grp_addr, int port, const char *local)
return NULL; return NULL;
} }
/* don't lookback */ u = (udp_t *) __mcast_new(grp_addr, port, sock);
do { /* don't loopback */
uint8_t loop = 0; udp_mcast_set_loop(u, 0);
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof loop); return u;
} while (0);
return (udp_t *) __mcast_new(grp_addr, port, sock);
} }
int udp_mcast_set_loop(udp_t *u, int on) int udp_mcast_set_loop(udp_t *u, int on)
@ -175,6 +177,7 @@ udp_t *udp_open_mcast_write_only(const char *group, int port, const char *local)
struct in_addr localInterface; struct in_addr localInterface;
struct sockaddr_in groupSock; struct sockaddr_in groupSock;
int sd; int sd;
udp_t *u;
sd = socket(AF_INET, SOCK_DGRAM, 0); sd = socket(AF_INET, SOCK_DGRAM, 0);
if(sd < 0) { if(sd < 0) {
@ -196,8 +199,9 @@ udp_t *udp_open_mcast_write_only(const char *group, int port, const char *local)
close(sd); close(sd);
return NULL; return NULL;
} }
u = (udp_t *)__mcast_new(group, port, sd);
return (udp_t *)__mcast_new(group, port, sd); udp_mcast_set_loop(u, 0);
return u;
} }
udp_t *udp_open_mcast_read_only(const char *grp_addr, int port, const char *local) udp_t *udp_open_mcast_read_only(const char *grp_addr, int port, const char *local)
@ -266,4 +270,3 @@ int getip(const char *ethx, char *addr, int len)
close(fd); close(fd);
return ret; return ret;
} }

27
udp.h

@ -1,8 +1,7 @@
#ifndef __UDP_NEWC_H__ #ifndef __UDP_NEWC_H__
#define __UDP_NEWC_H__ #define __UDP_NEWC_H__
typedef struct udp udp_t; typedef struct udp udp_t;
struct udp { struct udpops {
int sock;
int (*bind)(udp_t *, const char *local_ip, int local_port); int (*bind)(udp_t *, const char *local_ip, int local_port);
int (*connect)(udp_t *, const char *remote_ip, int remote_port); int (*connect)(udp_t *, const char *remote_ip, int remote_port);
int (*send)(udp_t *, void *buf, int len); int (*send)(udp_t *, void *buf, int len);
@ -10,6 +9,11 @@ struct udp {
int (*close)(udp_t *); int (*close)(udp_t *);
}; };
struct udp {
struct udpops *uops;
int sock;
};
udp_t *udp_open(void); udp_t *udp_open(void);
udp_t *udp_open_mcast(const char *group, int port, const char *local_if); udp_t *udp_open_mcast(const char *group, int port, const char *local_if);
udp_t *udp_open_mcast_write_only(const char *group, int port, const char *local); udp_t *udp_open_mcast_write_only(const char *group, int port, const char *local);
@ -17,5 +21,22 @@ udp_t *udp_open_mcast_read_only(const char *grp_addr, int port, const char *loca
int udp_mcast_set_loop(udp_t *u, int on); int udp_mcast_set_loop(udp_t *u, int on);
int getip(const char *ethx, char *addr, int len); int getip(const char *ethx, char *addr, int len);
#endif static inline int udp_bind(udp_t *u, const char *local_ip, int local_port) {
return u->uops->bind(u, local_ip, local_port);
}
static inline int udp_connect(udp_t *u, const char *remote_ip, int remote_port) {
return u->uops->connect(u, remote_ip, remote_port);
}
static inline int udp_send(udp_t *u, void *buf, int len) {
return u->uops->send(u, buf, len);
}
static inline int udp_recv(udp_t *u, void *buf, int len) {
return u->uops->recv(u, buf, len);
}
static inline int udp_close(udp_t *u) {
return u->uops->close(u);
}
#endif

3
udp_readable.c

@ -37,7 +37,6 @@ udp_readable_t *udp_readable_open(size_t alloc_size, udp_t *u)
void udp_readable_close(udp_readable_t *ur) void udp_readable_close(udp_readable_t *ur)
{ {
udp_readable_end(ur); udp_readable_end(ur);
ur->udp->close(ur->udp); udp_close(ur->udp);
free(ur); free(ur);
} }

1
udp_readable.h

@ -16,4 +16,3 @@ void udp_readable_end(udp_readable_t *ur);
udp_readable_t *udp_readable_open(size_t alloc_size, udp_t *u); udp_readable_t *udp_readable_open(size_t alloc_size, udp_t *u);
void udp_readable_close(udp_readable_t *); void udp_readable_close(udp_readable_t *);
#endif #endif

13
wan.c

@ -50,7 +50,7 @@ static void __is_readable(udp_readable_t *ur)
wan_t *wn = (wan_t *)ur; wan_t *wn = (wan_t *)ur;
udp_t *u = ur->udp; udp_t *u = ur->udp;
if ((len = u->recv(u, data, sizeof data)) <= 0) if ((len = udp_recv(u, data, sizeof data)) <= 0)
return; return;
#ifdef WAN_DEBUG #ifdef WAN_DEBUG
@ -80,7 +80,7 @@ static void __on_uplink(struct codec_complete *cc, void *msgType, uint8_t *buf,
(void) msgType; (void) msgType;
u->send(u, buf, len); udp_send(u, buf, len);
} }
static void __on_ptt(struct lanmsg_handler *lh, lan_t *ln, struct MsgCmd *hdr, uint8_t posId, int on) static void __on_ptt(struct lanmsg_handler *lh, lan_t *ln, struct MsgCmd *hdr, uint8_t posId, int on)
@ -118,7 +118,7 @@ static void __on_ptt(struct lanmsg_handler *lh, lan_t *ln, struct MsgCmd *hdr, u
x = getcs(buf, pos); x = getcs(buf, pos);
buf[pos++] = x; buf[pos++] = x;
buf[pos++] = 0x14; buf[pos++] = 0x14;
u->send(u, buf, pos); udp_send(u, buf, pos);
lan_ptt_response(ln, on ? RESP_PTT_ON : RESP_PTT_OFF, hdr, RESP_PTT_OK); lan_ptt_response(ln, on ? RESP_PTT_ON : RESP_PTT_OFF, hdr, RESP_PTT_OK);
} }
@ -142,7 +142,7 @@ static void __on_status(struct lanmsg_handler *lh, uint8_t id, uint8_t status)
sbuf = (uint8_t *)&wn->_stBuf; sbuf = (uint8_t *)&wn->_stBuf;
wn->_stBuf.checkNum = getcs(sbuf,len); wn->_stBuf.checkNum = getcs(sbuf,len);
len = wn->stsock->send(wn->stsock, &wn->_stBuf, sizeof wn->_stBuf); len = udp_send(wn->stsock, &wn->_stBuf, sizeof wn->_stBuf);
if (len < 0) { if (len < 0) {
log_printf("%s:%d errno (%d) %s\n", __FILE__, __LINE__, errno, strerror(errno)); log_printf("%s:%d errno (%d) %s\n", __FILE__, __LINE__, errno, strerror(errno));
} }
@ -161,7 +161,7 @@ wan_t* wan_new(const char *group_addr, int port, const char *wlan_if, int stport
if ((sts = udp_open_mcast(group_addr, stport, wlan_if)) == NULL) { if ((sts = udp_open_mcast(group_addr, stport, wlan_if)) == NULL) {
log_printf("'%s[%d]: can't create status multicast socket\n", __FILE__, __LINE__); log_printf("'%s[%d]: can't create status multicast socket\n", __FILE__, __LINE__);
udp->close(udp); udp_close(udp);
return NULL; return NULL;
} }
wn = (wan_t *)udp_readable_open(sizeof *wn, udp); wn = (wan_t *)udp_readable_open(sizeof *wn, udp);
@ -189,7 +189,6 @@ wan_t* wan_new(const char *group_addr, int port, const char *wlan_if, int stport
void wan_free(wan_t *wn) void wan_free(wan_t *wn)
{ {
wn->stsock->close(wn->stsock); udp_close(wn->stsock);
udp_readable_close(&wn->base); udp_readable_close(&wn->base);
} }

Loading…
Cancel
Save