]> granicus.if.org Git - rtmpdump/commitdiff
Tweak SendChunk to use a single WriteN call
authorhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Sat, 9 Jan 2010 07:09:13 +0000 (07:09 +0000)
committerhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Sat, 9 Jan 2010 07:09:13 +0000 (07:09 +0000)
git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@227 400ebc74-4327-4243-bc38-086b20814532

rtmp.c

diff --git a/rtmp.c b/rtmp.c
index 2dfc717e57f9712bf476923faac6937c8234231e..aafc3cff93d483bb03d62c7f93a254ebb6e6b017 100644 (file)
--- a/rtmp.c
+++ b/rtmp.c
@@ -2177,14 +2177,22 @@ bool
 RTMP_SendChunk(RTMP *r, RTMPChunk *chunk)
 {
   bool wrote;
+  char hbuf[RTMP_MAX_HEADER_SIZE];
 
   Log(LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_socket, chunk->c_chunkSize);
   LogHexString(LOGDEBUG2, chunk->c_header, chunk->c_headerSize);
   if (chunk->c_chunkSize)
-    LogHexString(LOGDEBUG2, chunk->c_chunk, chunk->c_chunkSize);
-  wrote = WriteN(r, chunk->c_header, chunk->c_headerSize);
-  if (wrote && chunk->c_chunkSize)
-    wrote = WriteN(r, chunk->c_chunk, chunk->c_chunkSize);
+    {
+      char *ptr = chunk->c_chunk - chunk->c_headerSize;
+      LogHexString(LOGDEBUG2, chunk->c_chunk, chunk->c_chunkSize);
+      /* save header bytes we're about to overwrite */
+      memcpy(hbuf, ptr, chunk->c_headerSize);
+      memcpy(ptr, chunk->c_header, chunk->c_headerSize);
+      wrote = WriteN(r, ptr, chunk->c_headerSize + chunk->c_chunkSize);
+      memcpy(ptr, hbuf, chunk->c_headerSize);
+    }
+  else
+    wrote = WriteN(r, chunk->c_header, chunk->c_headerSize);
   return wrote;
 }