Codebase list squeezelite / 8977b16
support local file direct access on windows Adrian Smith 10 years ago
2 changed file(s) with 41 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
813813
814814 } else {
815815
816 struct sockaddr_in our_addr;
817 socklen_t len;
818
816819 LOG_INFO("connected");
817820
818821 var_cap[0] = '\0';
819
820822 failed_connect = 0;
821823
822 #if !WIN
823824 // check if this is a local player now we are connected & signal to server via 'loc' format
824825 // this requires LocalPlayer server plugin to enable direct file access
825 // not supported on windows at present as the poll in stream.c does not work for file access
826 struct sockaddr_in our_addr;
827 socklen_t len;
828826 len = sizeof(our_addr);
829827 getsockname(sock, (struct sockaddr *) &our_addr, &len);
830828
832830 LOG_INFO("local player");
833831 strcat(var_cap, ",loc");
834832 }
835 #endif
836833
837834 // add on any capablity to be sent to the new server
838835 if (new_server_cap) {
8181 size_t space;
8282
8383 LOCK;
84
8485 space = min(_buf_space(streambuf), _buf_cont_write(streambuf));
85 UNLOCK;
86
87 if (fd >= 0 && stream.state > STREAMING_WAIT && space) {
86
87 if (fd < 0 || !space || stream.state <= STREAMING_WAIT) {
88 UNLOCK;
89 usleep(100000);
90 continue;
91 }
92
93 if (stream.state == STREAMING_FILE) {
94
95 int n = read(fd, streambuf->writep, space);
96 if (n == 0) {
97 LOG_INFO("end of stream");
98 _disconnect(DISCONNECT, DISCONNECT_OK);
99 }
100 if (n > 0) {
101 _buf_inc_writep(streambuf, n);
102 stream.bytes += n;
103 LOG_SDEBUG("streambuf read %d bytes", n);
104 }
105 if (n < 0) {
106 LOG_WARN("error reading: %s", strerror(last_error()));
107 _disconnect(DISCONNECT, REMOTE_DISCONNECT);
108 }
109
110 UNLOCK;
111 continue;
112
113 } else {
114
88115 pollinfo.fd = fd;
89116 pollinfo.events = POLLIN;
90117 if (stream.state == SEND_HEADERS) {
91118 pollinfo.events |= POLLOUT;
92119 }
93 } else {
94 usleep(100000);
95 continue;
96120 }
121
122 UNLOCK;
97123
98124 if (poll(&pollinfo, 1, 100)) {
99125
217243 space = min(space, stream.meta_next);
218244 }
219245
220 n = stream.state == STREAMING_FILE ? read(fd, streambuf->writep, space) : recv(fd, streambuf->writep, space, 0);
246 n = stream.state == recv(fd, streambuf->writep, space, 0);
221247 if (n == 0) {
222248 LOG_INFO("end of stream");
223249 _disconnect(DISCONNECT, DISCONNECT_OK);
314340
315341 LOG_INFO("opening local file: %s", stream.header);
316342
343 #if WIN
344 fd = open(stream.header, O_RDONLY | O_BINARY);
345 #else
317346 fd = open(stream.header, O_RDONLY);
347 #endif
348
318349 stream.state = STREAMING_FILE;
319350 if (fd < 0) {
320351 LOG_INFO("can't open file: %s", stream.header);