Skip to content

Commit

Permalink
rtsp: send responses as single packets
Browse files Browse the repository at this point in the history
Under some circumstances, RTSP responses would be split into multiple
packets. This causes Airfoil to barf, as it interprets the end of the
packet as the end of the response. Since TCP_CORK is not portable, this
fix buffers the packet on the stack before using a single write.
This fixes issue #213.
  • Loading branch information
abrasive committed Aug 25, 2013
1 parent c267c8e commit 5ed2af1
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions rtsp.c
Expand Up @@ -331,22 +331,32 @@ static rtsp_message * rtsp_read_request(int fd) {
}

static void msg_write_response(int fd, rtsp_message *resp) {
char rbuf[30];
int nrbuf;
nrbuf = snprintf(rbuf, sizeof(rbuf),
"RTSP/1.0 %d %s\r\n", resp->respcode,
resp->respcode==200 ? "OK" : "Error");
write(fd, rbuf, nrbuf);
debug(1, "sending response: %s", rbuf);
int i;
char pkt[1024];
int pktfree = sizeof(pkt);
char *p = pkt;
int i, n;

n = snprintf(p, pktfree,
"RTSP/1.0 %d %s\r\n", resp->respcode,
resp->respcode==200 ? "OK" : "Error");
debug(1, "sending response: %s", pkt);
pktfree -= n;
p += n;

for (i=0; i<resp->nheaders; i++) {
debug(2, " %s: %s\n", resp->name[i], resp->value[i]);
write(fd, resp->name[i], strlen(resp->name[i]));
write(fd, ": ", 2);
write(fd, resp->value[i], strlen(resp->value[i]));
write(fd, "\r\n", 2);
n = snprintf(p, pktfree, "%s: %s\r\n", resp->name[i], resp->value[i]);
pktfree -= n;
p += n;
if (pktfree <= 0)
die("Attempted to write overlong RTSP packet");
}
write(fd, "\r\n", 2);

if (pktfree < 3)
die("Attempted to write overlong RTSP packet");

strcpy(p, "\r\n");
write(fd, pkt, p-pkt+2);
}

static void handle_options(rtsp_conn_info *conn,
Expand Down

2 comments on commit 5ed2af1

@mkormendy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muhahhahhahha ... It causes Airfoil to barf! Lol best commit comment yet!

@mkormendy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q. Does this fix those packet resend requests?

Please sign in to comment.