mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
check udp address, see #852
This commit is contained in:
@@ -602,12 +602,26 @@ udp_socket_address(struct socket *s, const uint8_t udp_address[UDP_ADDRESS_SIZE]
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drop_udp(struct socket_server *ss, struct socket *s, struct wb_list *list, struct write_buffer *tmp) {
|
||||||
|
s->wb_size -= tmp->sz;
|
||||||
|
list->head = tmp->next;
|
||||||
|
if (list->head == NULL)
|
||||||
|
list->tail = NULL;
|
||||||
|
write_buffer_free(ss,tmp);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
send_list_udp(struct socket_server *ss, struct socket *s, struct wb_list *list, struct socket_message *result) {
|
send_list_udp(struct socket_server *ss, struct socket *s, struct wb_list *list, struct socket_message *result) {
|
||||||
while (list->head) {
|
while (list->head) {
|
||||||
struct write_buffer * tmp = list->head;
|
struct write_buffer * tmp = list->head;
|
||||||
union sockaddr_all sa;
|
union sockaddr_all sa;
|
||||||
socklen_t sasz = udp_socket_address(s, tmp->udp_address, &sa);
|
socklen_t sasz = udp_socket_address(s, tmp->udp_address, &sa);
|
||||||
|
if (sasz == 0) {
|
||||||
|
fprintf(stderr, "socket-server : udp (%d) type mismatch.\n", s->id);
|
||||||
|
drop_udp(ss, s, list, tmp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int err = sendto(s->fd, tmp->ptr, tmp->sz, 0, &sa.s, sasz);
|
int err = sendto(s->fd, tmp->ptr, tmp->sz, 0, &sa.s, sasz);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
@@ -616,16 +630,8 @@ send_list_udp(struct socket_server *ss, struct socket *s, struct wb_list *list,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "socket-server : udp (%d) sendto error %s.\n",s->id, strerror(errno));
|
fprintf(stderr, "socket-server : udp (%d) sendto error %s.\n",s->id, strerror(errno));
|
||||||
|
drop_udp(ss, s, list, tmp);
|
||||||
return -1;
|
return -1;
|
||||||
/* // ignore udp sendto error
|
|
||||||
|
|
||||||
result->opaque = s->opaque;
|
|
||||||
result->id = s->id;
|
|
||||||
result->ud = 0;
|
|
||||||
result->data = NULL;
|
|
||||||
|
|
||||||
return SOCKET_ERR;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s->wb_size -= tmp->sz;
|
s->wb_size -= tmp->sz;
|
||||||
@@ -830,6 +836,12 @@ send_socket(struct socket_server *ss, struct request_send * request, struct sock
|
|||||||
}
|
}
|
||||||
union sockaddr_all sa;
|
union sockaddr_all sa;
|
||||||
socklen_t sasz = udp_socket_address(s, udp_address, &sa);
|
socklen_t sasz = udp_socket_address(s, udp_address, &sa);
|
||||||
|
if (sasz == 0) {
|
||||||
|
// udp type mismatch, just drop it.
|
||||||
|
fprintf(stderr, "socket-server: udp socket (%d) type mistach.\n", id);
|
||||||
|
so.free_func(request->buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
int n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
||||||
if (n != so.sz) {
|
if (n != so.sz) {
|
||||||
append_sendbuffer_udp(ss,s,priority,request,udp_address);
|
append_sendbuffer_udp(ss,s,priority,request,udp_address);
|
||||||
@@ -1529,6 +1541,12 @@ socket_server_send(struct socket_server *ss, int id, const void * buffer, int sz
|
|||||||
} else {
|
} else {
|
||||||
union sockaddr_all sa;
|
union sockaddr_all sa;
|
||||||
socklen_t sasz = udp_socket_address(s, s->p.udp_address, &sa);
|
socklen_t sasz = udp_socket_address(s, s->p.udp_address, &sa);
|
||||||
|
if (sasz == 0) {
|
||||||
|
fprintf(stderr, "socket-server : udp (%d) type mismatch.\n", id);
|
||||||
|
socket_unlock(&l);
|
||||||
|
so.free_func((void *)buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
||||||
}
|
}
|
||||||
if (n<0) {
|
if (n<0) {
|
||||||
@@ -1796,6 +1814,11 @@ socket_server_udp_send(struct socket_server *ss, int id, const struct socket_udp
|
|||||||
send_object_init(ss, &so, (void *)buffer, sz);
|
send_object_init(ss, &so, (void *)buffer, sz);
|
||||||
union sockaddr_all sa;
|
union sockaddr_all sa;
|
||||||
socklen_t sasz = udp_socket_address(s, udp_address, &sa);
|
socklen_t sasz = udp_socket_address(s, udp_address, &sa);
|
||||||
|
if (sasz == 0) {
|
||||||
|
socket_unlock(&l);
|
||||||
|
so.free_func((void *)buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
int n = sendto(s->fd, so.buffer, so.sz, 0, &sa.s, sasz);
|
||||||
if (n >= 0) {
|
if (n >= 0) {
|
||||||
// sendto succ
|
// sendto succ
|
||||||
|
|||||||
Reference in New Issue
Block a user