annotate TOOLS/netstream.c @ 27025:e598c9756181

Ability for specifying TV standard individually for each TV channel. Slightly modified patch by Ildar devel at pop3 dot ru
author voroshil
date Sat, 14 Jun 2008 09:14:16 +0000
parents 8825552ee585
children 5a30f5bc23a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
1 /*
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
2 * Copyright (C) Alban Bedel - 04/2003
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
3 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
4 * This file is part of MPlayer.
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
5 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
7 * it under the terms of the GNU General Public License as published by
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
9 * (at your option) any later version.
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
10 *
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
14 * GNU General Public License for more details.
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
15 *
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
16 * You should have received a copy of the GNU General Public License along
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 26575
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
19 */
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
20
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
21 #include <stdlib.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
22 #include <stdio.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
23 #include <unistd.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
24 #include <inttypes.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
25 #include <errno.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
26 #include <signal.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
27 #include <sys/types.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
28
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
29 #include "config.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
30
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
31 #ifndef HAVE_WINSOCK2
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
32 #include <sys/socket.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
33 #include <netinet/in.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
34 #include <arpa/inet.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
35 #else
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
36 #include <winsock2.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
37 #include <ws2tcpip.h>
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
38 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
39
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
40 #include "stream/stream.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
41 #include "libmpdemux/demuxer.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
42 #include "mp_msg.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
43 #include "libavutil/common.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
44 #include "mpbswap.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
45
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
46 /// Netstream packets def and some helpers
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
47 #include "stream/netstream.h"
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
48
26963
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
49 // linking hacks
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
50 char *info_name;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
51 char *info_artist;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
52 char *info_genre;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
53 char *info_subject;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
54 char *info_copyright;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
55 char *info_sourceform;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
56 char *info_comment;
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
57
26963
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
58 char* out_filename = NULL;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
59 char* force_fourcc=NULL;
8825552ee585 Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents: 26743
diff changeset
60 char* passtmpfile="divx2pass.log";
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
61
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
62 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
63 #define usleep sleep
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
64 void strsep() {};
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
65 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
66
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
67 static unsigned short int port = 10000;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
68
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
69 typedef struct client_st client_t;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
70 struct client_st {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
71 int fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
72 stream_t* stream;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
73 client_t* next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
74 client_t* prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
75 };
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
76
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
77 static int write_error(int fd,char* msg) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
78 int len = strlen(msg) + 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
79 return write_packet(fd,NET_STREAM_ERROR,msg,len);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
80 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
81
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
82 static int net_stream_open(client_t* cl,char* url) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
83 int file_format=DEMUXER_TYPE_UNKNOWN;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
84 mp_net_stream_opened_t ret;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
85
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
86 if(cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
87 if(!write_error(cl->fd,"A stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
88 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
89 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
90 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
91
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
92 mp_msg(MSGT_NETST,MSGL_V,"Open stream %s\n",url);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
93 cl->stream = open_stream(url,NULL,&file_format);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
94 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
95 if(!write_error(cl->fd,"Open failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
96 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
97 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
98 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
99 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
100 stream_seek(cl->stream,cl->stream->start_pos);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
101 ret.file_format = file_format;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
102 ret.flags = cl->stream->flags;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
103 ret.sector_size = cl->stream->sector_size;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
104 ret.start_pos = cl->stream->start_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
105 ret.end_pos = cl->stream->end_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
106 net_stream_opened_2_me(&ret);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
107
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
108 if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t)))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
109 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
110 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
111 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
112
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
113 static int net_stream_fill_buffer(client_t* cl,uint16_t max_len) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
114 int r;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
115 mp_net_stream_packet_t *pack;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
116
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
117 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
118 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
119 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
120 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
121 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
122 if(max_len == 0) {
24595
85f669a84e7a cosmetics: misc typo fixes
diego
parents: 24181
diff changeset
123 if(!write_error(cl->fd,"Fill buffer called with 0 length\n"))
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
124 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
125 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
126 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
127 pack = malloc(max_len + sizeof(mp_net_stream_packet_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
128 pack->cmd = NET_STREAM_OK;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
129 r = stream_read(cl->stream,pack->data,max_len);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
130 pack->len = le2me_16(r + sizeof(mp_net_stream_packet_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
131 if(!net_write(cl->fd,(char*)pack,le2me_16(pack->len))) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
132 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
133 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
134 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
135 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
136 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
137 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
138
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
139 static int net_stream_seek(client_t* cl, uint64_t pos) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
140
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
141 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
142 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
143 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
144 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
145 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
146
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
147 if(!stream_seek(cl->stream,(off_t)pos)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
148 if(!write_error(cl->fd,"Seek failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
149 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
150 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
151 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
152 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
153 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
154 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
155 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
156
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
157 static int net_stream_reset(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
158 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
159 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
160 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
161 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
162 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
163 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
164 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
165 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
166 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
167 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
168
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
169 static int net_stream_close(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
170 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
171 if(!write_error(cl->fd,"No stream is currently opened\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
172 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
173 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
174 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
175
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
176 free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
177 cl->stream = NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
178
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
179 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
180 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
181 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
182 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
183
26575
1ca484e74f18 Mark all functions that are only used within the file as static.
diego
parents: 25310
diff changeset
184 static int handle_client(client_t* cl,mp_net_stream_packet_t* pack) {
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
185
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
186 if(!pack)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
187 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
188
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
189 switch(pack->cmd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
190 case NET_STREAM_OPEN:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
191 if(((char*)pack)[pack->len-1] != '\0') {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
192 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid open packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
193 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
194 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
195 return net_stream_open(cl,pack->data);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
196 case NET_STREAM_FILL_BUFFER:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
197 if(pack->len != sizeof(mp_net_stream_packet_t) + 2) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
198 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
199 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
200 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
201 return net_stream_fill_buffer(cl,le2me_16(*((uint16_t*)pack->data)));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
202 case NET_STREAM_SEEK:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
203 if(pack->len != sizeof(mp_net_stream_packet_t) + 8) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
204 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
205 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
206 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
207 return net_stream_seek(cl,le2me_64(*((uint64_t*)pack->data)));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
208 case NET_STREAM_RESET:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
209 return net_stream_reset(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
210 case NET_STREAM_CLOSE:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
211 if(pack->len != sizeof(mp_net_stream_packet_t)){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
212 mp_msg(MSGT_NETST,MSGL_WARN,"Got invalid fill buffer packet\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
213 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
214 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
215 return net_stream_close(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
216 default:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
217 mp_msg(MSGT_NETST,MSGL_WARN,"Got unknown command %d\n",pack->cmd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
218 if(!write_error(cl->fd,"Unknown command\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
219 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
220 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
221 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
222 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
223
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
224 static client_t* add_client(client_t *head,int fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
225 client_t *new = calloc(1,sizeof(client_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
226 new->fd = fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
227 if(!head) return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
228 new->next = head;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
229 head->prev = new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
230 return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
231 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
232
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
233 static int make_fd_set(fd_set* fds, client_t** _cl, int listen) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
234 int max_fd = listen;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
235 client_t *cl = *_cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
236 FD_ZERO(fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
237 FD_SET(listen,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
238 while(cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
239 // Remove this client
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
240 if(cl->fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
241 client_t* f = cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
242 if(cl->prev) cl->prev->next = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
243 if(cl->next) cl->next->prev = cl->prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
244 if(cl->stream) free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
245 if(!cl->prev) // Remove the head
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
246 *_cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
247 cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
248 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
249 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
250 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
251 FD_SET(cl->fd,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
252 if(cl->fd > max_fd) max_fd = cl->fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
253 cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
254 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
255 return max_fd+1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
256 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
257
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
258 /// Hack to 'cleanly' exit
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
259 static int run_server = 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
260
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
261 void exit_sig(int sig) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
262 static int count = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
263 sig++; // gcc warning
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
264 count++;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
265 if(count==3) exit(1);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
266 if(count > 3)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
267 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
268 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
269 #else
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
270 kill(getpid(),SIGKILL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
271 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
272 run_server = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
273 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
274
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
275 static int main_loop(int listen_fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
276 client_t *clients = NULL,*iter;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
277 fd_set fds;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
278
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
279 signal(SIGTERM,exit_sig); // kill
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
280 #ifndef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
281 signal(SIGHUP,exit_sig); // kill -HUP / xterm closed
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
282 signal(SIGINT,exit_sig); // Interrupt from keyboard
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
283 signal(SIGQUIT,exit_sig); // Quit from keyboard
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
284 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
285
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
286 while(run_server) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
287 int sel_n = make_fd_set(&fds,&clients,listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
288 int n = select(sel_n,&fds,NULL,NULL,NULL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
289 if(n < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
290 if(errno == EINTR)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
291 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
292 mp_msg(MSGT_NETST,MSGL_FATAL,"Select error: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
293 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
294 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
295 // New connection
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
296 if(FD_ISSET(listen_fd,&fds)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
297 struct sockaddr_in addr;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
298 socklen_t slen = sizeof(struct sockaddr_in);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
299 int client_fd = accept(listen_fd,(struct sockaddr*)&addr,&slen);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
300 if(client_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
301 mp_msg(MSGT_NETST,MSGL_ERR,"accept failed: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
302 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
303 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
304 mp_msg(MSGT_NETST,MSGL_V,"New client from %s\n",inet_ntoa(addr.sin_addr));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
305 clients = add_client(clients,client_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
306 if(n == 1) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
307 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
308 // Look for the clients
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
309 for(iter = clients ; iter ; iter = iter->next) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
310 mp_net_stream_packet_t* pack;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
311 if(!FD_ISSET(iter->fd,&fds)) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
312 pack = read_packet(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
313 if(!pack) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
314 close(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
315 iter->fd = -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
316 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
317 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
318 if(!handle_client(iter,pack)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
319 close(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
320 iter->fd = -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
321 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
322 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
323 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
324 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
325 mp_msg(MSGT_NETST,MSGL_INFO,"Exit ....\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
326 close(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
327 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
328 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
329 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
330 while(clients) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
331 client_t* f = clients;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
332 if(f->stream) free_stream(f->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
333 if(f->fd > 0) close(f->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
334 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
335 clients = clients->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
336 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
337 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
338 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
339
25310
e3c5cd98d59a Remove unused parameters from main(), fixes the warnings:
diego
parents: 24595
diff changeset
340 int main(void) {
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
341 int listen_fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
342 struct sockaddr_in addr;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
343
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
344 mp_msg_init();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
345 // mp_msg_set_level(verbose+MSGL_STATUS);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
346
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
347 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
348 WSADATA wsaData;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
349 WSAStartup(MAKEWORD(1,1), &wsaData);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
350 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
351 listen_fd = socket(AF_INET, SOCK_STREAM, 0);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
352 if(listen_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
353 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to create listen_fd: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
354 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
355 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
356 memset(&addr,0,sizeof(struct sockaddr));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
357 addr.sin_addr.s_addr = INADDR_ANY;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
358 addr.sin_port = htons(port);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
359 addr.sin_family = AF_INET;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
360 if(bind(listen_fd,(struct sockaddr*)&addr,sizeof(struct sockaddr))) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
361 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to bind listen socket: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
362 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
363 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
364
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
365
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
366 if(listen(listen_fd,1)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
367 mp_msg(MSGT_NETST,MSGL_FATAL,"Failed to turn the socket in listen state: %s\n",strerror(errno));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
368 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
369 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
370 return main_loop(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
371 }