annotate TOOLS/netstream.c @ 36479:51550da54c58

Rearrange encodings. Try to be somewhat more systematic.
author ib
date Mon, 13 Jan 2014 19:03:57 +0000
parents 08d53b704b88
children
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
28408
a1dbbfeebfd7 HAVE_WINSOCK2_H is now a 0/1 definition.
diego
parents: 27745
diff changeset
31 #if !HAVE_WINSOCK2_H
22855
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
27745
a5ed200519dc Rename stream/netstream.h to stream/stream_netstream.h; netstream.h to make it
diego
parents: 27663
diff changeset
47 #include "stream/stream_netstream.h"
22855
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 static unsigned short int port = 10000;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
63
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
64 typedef struct client_st client_t;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
65 struct client_st {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
66 int fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
67 stream_t* stream;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
68 client_t* next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
69 client_t* prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
70 };
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
71
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
72 static int write_error(int fd,char* msg) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
73 int len = strlen(msg) + 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
74 return write_packet(fd,NET_STREAM_ERROR,msg,len);
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 net_stream_open(client_t* cl,char* url) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
78 int file_format=DEMUXER_TYPE_UNKNOWN;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
79 mp_net_stream_opened_t ret;
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 if(cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
82 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
83 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
84 return 1;
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
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
87 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
88 cl->stream = open_stream(url,NULL,&file_format);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
89 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
90 if(!write_error(cl->fd,"Open failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
91 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
92 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
93 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
94 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
95 stream_seek(cl->stream,cl->stream->start_pos);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
96 ret.file_format = file_format;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
97 ret.flags = cl->stream->flags;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
98 ret.sector_size = cl->stream->sector_size;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
99 ret.start_pos = cl->stream->start_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
100 ret.end_pos = cl->stream->end_pos;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
101 net_stream_opened_2_me(&ret);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
102
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
103 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
104 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
105 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
106 }
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 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
109 int r;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
110 mp_net_stream_packet_t *pack;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
111
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
112 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
113 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
114 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
115 return 1;
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(max_len == 0) {
24595
85f669a84e7a cosmetics: misc typo fixes
diego
parents: 24181
diff changeset
118 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
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 pack = malloc(max_len + sizeof(mp_net_stream_packet_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
123 pack->cmd = NET_STREAM_OK;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
124 r = stream_read(cl->stream,pack->data,max_len);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
125 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
126 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
127 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
128 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
129 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
130 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
131 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
132 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
133
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
134 static int net_stream_seek(client_t* cl, uint64_t pos) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
135
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
136 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
137 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
138 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
139 return 1;
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
35878
08d53b704b88 Remove useless cast (at best it will break things).
reimar
parents: 31337
diff changeset
142 if(!stream_seek(cl->stream,pos)) {
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
143 if(!write_error(cl->fd,"Seek failed\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
144 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
145 return 1;
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(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
148 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
149 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
150 }
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 static int net_stream_reset(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
153 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
154 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
155 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
156 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
157 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
158 stream_reset(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
159 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
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
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
164 static int net_stream_close(client_t* cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
165 if(!cl->stream) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
166 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
167 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
168 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
169 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
170
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
171 free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
172 cl->stream = NULL;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
173
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
174 if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
175 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
176 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
177 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
178
26575
1ca484e74f18 Mark all functions that are only used within the file as static.
diego
parents: 25310
diff changeset
179 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
180
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
181 if(!pack)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
182 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
183
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
184 switch(pack->cmd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
185 case NET_STREAM_OPEN:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
186 if(((char*)pack)[pack->len-1] != '\0') {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
187 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
188 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
189 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
190 return net_stream_open(cl,pack->data);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
191 case NET_STREAM_FILL_BUFFER:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
192 if(pack->len != sizeof(mp_net_stream_packet_t) + 2) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
193 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
194 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
195 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
196 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
197 case NET_STREAM_SEEK:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
198 if(pack->len != sizeof(mp_net_stream_packet_t) + 8) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
199 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
200 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
201 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
202 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
203 case NET_STREAM_RESET:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
204 return net_stream_reset(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
205 case NET_STREAM_CLOSE:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
206 if(pack->len != sizeof(mp_net_stream_packet_t)){
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
207 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
208 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
209 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
210 return net_stream_close(cl);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
211 default:
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
212 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
213 if(!write_error(cl->fd,"Unknown command\n"))
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
214 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
215 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
216 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
217 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
218
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
219 static client_t* add_client(client_t *head,int fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
220 client_t *new = calloc(1,sizeof(client_t));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
221 new->fd = fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
222 if(!head) return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
223 new->next = head;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
224 head->prev = new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
225 return new;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
226 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
227
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
228 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
229 int max_fd = listen;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
230 client_t *cl = *_cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
231 FD_ZERO(fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
232 FD_SET(listen,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
233 while(cl) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
234 // Remove this client
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
235 if(cl->fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
236 client_t* f = cl;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
237 if(cl->prev) cl->prev->next = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
238 if(cl->next) cl->next->prev = cl->prev;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
239 if(cl->stream) free_stream(cl->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
240 if(!cl->prev) // Remove the head
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
241 *_cl = cl->next;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
242 cl = cl->next;
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
243 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
244 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
245 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
246 FD_SET(cl->fd,fds);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
247 if(cl->fd > max_fd) max_fd = cl->fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
248 cl = cl->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
249 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
250 return max_fd+1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
251 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
252
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
253 /// Hack to 'cleanly' exit
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
254 static int run_server = 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
255
31337
3fd6746f539c Mark exit_sig() function as static; it is only used within the file.
diego
parents: 29263
diff changeset
256 static void exit_sig(int sig) {
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
257 static int count = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
258 sig++; // gcc warning
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
259 count++;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
260 if(count==3) exit(1);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
261 if(count > 3)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
262 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
263 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
264 #else
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
265 kill(getpid(),SIGKILL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
266 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
267 run_server = 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
268 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
269
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
270 static int main_loop(int listen_fd) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
271 client_t *clients = NULL,*iter;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
272 fd_set fds;
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 signal(SIGTERM,exit_sig); // kill
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
275 #ifndef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
276 signal(SIGHUP,exit_sig); // kill -HUP / xterm closed
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
277 signal(SIGINT,exit_sig); // Interrupt from keyboard
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
278 signal(SIGQUIT,exit_sig); // Quit from keyboard
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
279 #endif
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
280
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
281 while(run_server) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
282 int sel_n = make_fd_set(&fds,&clients,listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
283 int n = select(sel_n,&fds,NULL,NULL,NULL);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
284 if(n < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
285 if(errno == EINTR)
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
286 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
287 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
288 return 1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
289 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
290 // New connection
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
291 if(FD_ISSET(listen_fd,&fds)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
292 struct sockaddr_in addr;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
293 socklen_t slen = sizeof(struct sockaddr_in);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
294 int client_fd = accept(listen_fd,(struct sockaddr*)&addr,&slen);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
295 if(client_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
296 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
297 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
298 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
299 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
300 clients = add_client(clients,client_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
301 if(n == 1) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
302 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
303 // Look for the clients
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
304 for(iter = clients ; iter ; iter = iter->next) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
305 mp_net_stream_packet_t* pack;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
306 if(!FD_ISSET(iter->fd,&fds)) continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
307 pack = read_packet(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
308 if(!pack) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
309 close(iter->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
310 iter->fd = -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
311 continue;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
312 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
313 if(!handle_client(iter,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 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
317 free(pack);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
318 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
319 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
320 mp_msg(MSGT_NETST,MSGL_INFO,"Exit ....\n");
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
321 close(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
322 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
323 WSACleanup();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
324 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
325 while(clients) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
326 client_t* f = clients;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
327 if(f->stream) free_stream(f->stream);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
328 if(f->fd > 0) close(f->fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
329 free(f);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
330 clients = clients->next;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
331 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
332 return 0;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
333 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
334
25310
e3c5cd98d59a Remove unused parameters from main(), fixes the warnings:
diego
parents: 24595
diff changeset
335 int main(void) {
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
336 int listen_fd;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
337 struct sockaddr_in addr;
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 mp_msg_init();
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
340 // mp_msg_set_level(verbose+MSGL_STATUS);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
341
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
342 #ifdef __MINGW32__
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
343 WSADATA wsaData;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
344 WSAStartup(MAKEWORD(1,1), &wsaData);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
345 #endif
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
346 listen_fd = socket(AF_INET, SOCK_STREAM, 0);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
347 if(listen_fd < 0) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
348 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
349 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
350 }
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
351 memset(&addr,0,sizeof(struct sockaddr));
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
352 addr.sin_addr.s_addr = INADDR_ANY;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
353 addr.sin_port = htons(port);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
354 addr.sin_family = AF_INET;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
355 if(bind(listen_fd,(struct sockaddr*)&addr,sizeof(struct sockaddr))) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
356 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
357 return -1;
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
358 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28408
diff changeset
359
22855
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
360
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
361 if(listen(listen_fd,1)) {
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
362 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
363 return -1;
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 return main_loop(listen_fd);
d258dd05e0ab Move netstream.c out of its single-file subdirectory.
diego
parents:
diff changeset
366 }