+ /* Perhaps a connection has arrived */
+ if(fds[listen_slot].revents & POLLIN) {
+ struct sockaddr_un addr;
+ socklen_t addrlen = sizeof addr;
+ uint32_t l;
+ char id[24];
+
+ if((fd = accept(listenfd, &addr, &addrlen)) >= 0) {
+ if(read(fd, &l, sizeof l) < 4) {
+ error(errno, "reading length from inbound connection");
+ xclose(fd);
+ } else if(l >= sizeof id) {
+ error(0, "id length too long");
+ xclose(fd);
+ } else if(read(fd, id, l) < (ssize_t)l) {
+ error(errno, "reading id from inbound connection");
+ xclose(fd);
+ } else {
+ id[l] = 0;
+ D(("id %s fd %d", id, fd));
+ t = findtrack(id, 1/*create*/);
+ write(fd, "", 1); /* write an ack */
+ if(t->fd != -1) {
+ error(0, "got a connection for a track that already has one");
+ xclose(fd);
+ } else {
+ nonblock(fd);
+ t->fd = fd; /* yay */
+ }
+ }
+ } else
+ error(errno, "accept");
+ }