Skip to content

Commit

Permalink
Fix error paths in output_{udp,rtp}.c and add socket_close
Browse files Browse the repository at this point in the history
  • Loading branch information
flohoff committed Dec 4, 2008
1 parent c40b845 commit 61a0a29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion output_rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ static void output_init_rtp_rtcp(struct output_s *o) {
#endif

int output_init_rtp(struct output_s *o) {

o->sockfd=socket_open(NULL, 0);

if (o->sockfd < 0)
return -1;

socket_set_nonblock(o->sockfd);

/* Join multicast group if its a multicast address */
Expand Down
22 changes: 15 additions & 7 deletions output_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
#define UDP_MAX_TS ((1500-40)/TS_PACKET_SIZE)

int output_init_udp(struct output_s *o) {
struct sockaddr_in rsin;

memset(&rsin, 0, sizeof(struct sockaddr_in));

o->buffer=sb_init(UDP_MAX_TS, TS_PACKET_SIZE, 0);
if (o->buffer == NULL)
return 0;
if (!o->buffer)
goto errout1;

o->sockfd=socket_open(NULL, 0);
if (o->sockfd < 0)
goto errout2;

socket_set_nonblock(o->sockfd);
socket_connect(o->sockfd, o->remoteaddr, o->remoteport);

if (socket_connect(o->sockfd, o->remoteaddr, o->remoteport))
goto errout3;

/* Join Multicast group if its a multicast destination */
socket_join_multicast(o->sockfd, o->remoteaddr);
Expand All @@ -43,6 +44,13 @@ int output_init_udp(struct output_s *o) {
o->receiver=1;

return 1;

errout3:
socket_close(o->sockfd);
errout2:
sb_free(o->buffer);
errout1:
return 0;
}

void output_send_udp(struct output_s *o, uint8_t *tsp) {
Expand Down
4 changes: 4 additions & 0 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "output.h"
#include "simplebuffer.h"

void socket_close(int sock) {
close(sock);
}

int socket_open(char *laddr, int port) {
struct sockaddr_in lsin;
int sock;
Expand Down
1 change: 1 addition & 0 deletions socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ int socket_join_multicast(int sock, char *addr);
int socket_set_ttl(int sock, int ttl);
int socket_set_nonblock(int sock);
int socket_open(char *laddr, int port);
void socket_close(int sock);
int socket_connect(int sock, char *addr, int port);

0 comments on commit 61a0a29

Please sign in to comment.