hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CProtocolUDP.cpp
branchRCL_3
changeset 4 73ff0d268e1d
parent 0 a03f92240627
--- a/hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CProtocolUDP.cpp	Tue Feb 02 10:12:29 2010 +0200
+++ b/hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CProtocolUDP.cpp	Sat Feb 20 00:22:34 2010 +0200
@@ -132,22 +132,42 @@
         "CProtocolUDP::WriteFrameL(), peer port=%d, original port=%d" ),
         aPeerPort, aOriginalPort );
 
-    aSocketWriter.WriteL( KUDPPrefix );
-
-    TBuf8<KHexDecimalLength> portBuf;
-    portBuf.Format( KHexFormat, aPeerPort );
-    aSocketWriter.WriteL( portBuf );
-    aSocketWriter.WriteL( KPortSuffix );
+    TInt bufSize = 0;
+    bufSize += KUDPPrefix().Length();
+    bufSize += KHexDecimalLength;
+    bufSize += KPortSuffix().Length();
+    bufSize += KHexDecimalLength;
+    bufSize += KLengthSuffix().Length();
+    bufSize += aData.Length();
+    bufSize += KDataSuffix().Length();
+    bufSize += KMessageSuffix().Length();
+    
+    TBuf8<KHexDecimalLength> hexbuf;
+    HBufC8* buf = HBufC8::NewLC( bufSize );
+    TPtr8 ptr( buf->Des() );
+    
+    // Append UDP prefix
+    ptr.Append( KUDPPrefix );
 
-    TBuf8<KHexDecimalLength> lengthBuf;
-    lengthBuf.Format( KHexFormat, aData.Length() );
-    aSocketWriter.WriteL( lengthBuf );
+    // Append peer port
+    hexbuf.Format( KHexFormat, aPeerPort );
+    ptr.Append( hexbuf );
+    ptr.Append( KPortSuffix );
+
+    // Append data length
+    hexbuf.Format( KHexFormat, aData.Length() );
+    ptr.Append( hexbuf );
+    ptr.Append( KLengthSuffix );
 
-    aSocketWriter.WriteL( KLengthSuffix );
-    aSocketWriter.WriteL( aData );
-    aSocketWriter.WriteL( KDataSuffix );
+    // Append data
+    ptr.Append( aData );
+    ptr.Append( KDataSuffix );
+    ptr.Append( KMessageSuffix );
+    
+    // Write to socket
+    aSocketWriter.WriteL( *buf );
 
-    aSocketWriter.WriteL( KMessageSuffix );
+    CleanupStack::PopAndDestroy( buf );
     }
 
 // -----------------------------------------------------------------------------