Codebase list squeezelite / cc83c00
v0.9beta3 Fix some window related issues and implement our own version of poll (hopefully allows it to run on XP) Adrian Smith 11 years ago
5 changed file(s) with 65 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
6666 }
6767
6868 void sighandler(int signum) {
69 LOG_ERROR("signal");
7069 slimproto_stop();
7170 }
7271
674674
675675 } else {
676676
677 LOG_INFO("connected");
678
679 var_cap[0] = '\0';
680
681 #if !WIN
682 // check if this is a local player now we are connected & signal to server via 'loc' format
683 // this requires LocalPlayer server plugin to enable direct file access
684 // not supported on windows at present as the poll in stream.c does not work for file access
677685 struct sockaddr_in our_addr;
678686 socklen_t len;
679
680 LOG_INFO("connected");
681
682 var_cap[0] = '\0';
683
684 // check if this is a local player now we are connected & signal to server via 'loc' format
685 // this requires LocalPlayer server plugin to enable direct file access
686687 len = sizeof(our_addr);
687688 getsockname(sock, (struct sockaddr *) &our_addr, &len);
688
689
689690 if (our_addr.sin_addr.s_addr == serv_addr.sin_addr.s_addr) {
690691 LOG_INFO("local player");
691692 strcat(var_cap, ",loc");
692693 }
694 #endif
693695
694696 // add on any capablity to be sent to the new server
695697 if (new_server_cap) {
1717 *
1818 */
1919
20 #define VERSION "v0.9beta2"
20 #define VERSION "v0.9beta3"
2121
2222 // build detection
2323 #if defined(linux)
187187 #define in_addr_t u32_t
188188 #define socklen_t int
189189
190 #define poll WSAPoll // FIXME? - limits support to Vista and later
191
192190 #define dlopen(x, y) LoadLibrary((LPCTSTR)x)
193191 #define dlsym(x, y) (void *)GetProcAddress(x, y)
194 #define dlerror() GetLastError() ? "dlerror" : NULL
192 //dlerror implemented in utils.c
195193
196194 #endif
197195
272270 #if WIN
273271 void winsock_init(void);
274272 void winsock_close(void);
273 char *dlerror(void);
274 int poll(struct pollfd *fds, unsigned long numfds, int timeout);
275275 #endif
276276
277277 // buffer.c
4444 while (len) {
4545 n = send(fd, ptr, len, 0);
4646 if (n <= 0) {
47 if (n < 0 && errno == EAGAIN && try < 10) {
47 if (n < 0 && last_error() == EAGAIN && try < 10) {
4848 LOG_SDEBUG("retrying (%d) writing to socket", ++try);
4949 usleep(1000);
5050 continue;
7979 struct pollfd pollinfo = { fd, 0, 0 };
8080 size_t space;
8181
82 if (fd < 0) {
83 usleep(100000);
84 continue;
85 }
86
8782 LOCK;
8883 space = min(_buf_space(streambuf), _buf_cont_write(streambuf));
89
90 if (stream.state > STREAMING_WAIT && space) {
84 UNLOCK;
85
86 if (fd >= 0 && stream.state > STREAMING_WAIT && space) {
9187 pollinfo.events = POLLIN;
9288 if (stream.state == SEND_HEADERS) {
9389 pollinfo.events |= POLLOUT;
9490 }
91 } else {
92 usleep(100000);
93 continue;
9594 }
96
97 UNLOCK;
9895
9996 if (poll(&pollinfo, 1, 100)) {
10097
119116
120117 int n = recv(fd, &c, 1, 0);
121118 if (n <= 0) {
122 if (n < 0 && errno == EAGAIN) {
119 if (n < 0 && last_error() == EAGAIN) {
123120 UNLOCK;
124121 continue;
125122 }
161158 u8_t c;
162159 int n = recv(fd, &c, 1, 0);
163160 if (n <= 0) {
164 if (n < 0 && errno == EAGAIN) {
161 if (n < 0 && last_error() == EAGAIN) {
165162 UNLOCK;
166163 continue;
167164 }
178175 if (stream.meta_left) {
179176 int n = recv(fd, stream.header + stream.header_len, stream.meta_left, 0);
180177 if (n <= 0) {
181 if (n < 0 && errno == EAGAIN) {
178 if (n < 0 && last_error() == EAGAIN) {
182179 UNLOCK;
183180 continue;
184181 }
217214 LOG_INFO("end of stream");
218215 _disconnect(DISCONNECT, DISCONNECT_OK);
219216 }
220 if (n < 0 && errno != EAGAIN) {
217 if (n < 0 && last_error() != EAGAIN) {
221218 LOG_WARN("error reading: %s", strerror(last_error()));
222219 _disconnect(DISCONNECT, REMOTE_DISCONNECT);
223220 }
238238 void winsock_close(void) {
239239 WSACleanup();
240240 }
241 #endif
242
241
242 char *dlerror(void) {
243 static char ret[32];
244 int last = GetLastError();
245 if (last) {
246 sprintf(ret, "code: %i", last);
247 SetLastError(0);
248 return ret;
249 }
250 return NULL;
251 }
252
253 // this only implements numfds == 1
254 int poll(struct pollfd *fds, unsigned long numfds, int timeout) {
255 fd_set r, w;
256 struct timeval tv;
257 int ret;
258
259 FD_ZERO(&r);
260 FD_ZERO(&w);
261
262 if (fds[0].events & POLLIN) FD_SET(fds[0].fd, &r);
263 if (fds[0].events & POLLOUT) FD_SET(fds[0].fd, &w);
264
265 tv.tv_sec = timeout / 1000;
266 tv.tv_usec = 1000 * (timeout % 1000);
267
268 ret = select(fds[0].fd + 1, &r, &w, NULL, &tv);
269
270 if (ret < 0) return ret;
271
272 fds[0].revents = 0;
273 if (FD_ISSET(fds[0].fd, &r)) fds[0].revents |= POLLIN;
274 if (FD_ISSET(fds[0].fd, &w)) fds[0].revents |= POLLOUT;
275
276 return ret;
277 }
278
279 #endif
280