applayerpluginsandutils/httptransportplugins/httptransporthandler/csocket.cpp
branchRCL_3
changeset 13 26ce6fb6aee2
parent 5 337070b4fa18
child 18 5f1cd966e0d9
--- a/applayerpluginsandutils/httptransportplugins/httptransporthandler/csocket.cpp	Tue May 25 13:17:20 2010 +0300
+++ b/applayerpluginsandutils/httptransportplugins/httptransporthandler/csocket.cpp	Wed Jun 09 10:16:57 2010 +0300
@@ -43,6 +43,21 @@
 	return self;
 	}
 
+CSocket* CSocket::New(MCommsInfoProvider& aCommsInfoProvider, TSocketType aSocketType)
+    {
+    CSocket* self = new CSocket(aCommsInfoProvider);
+    if(self)
+        {
+        TInt error = self->Construct(aSocketType);
+        if(error != KErrNone)
+            {
+            delete self;
+            self = NULL;
+            }
+        }
+    return self;
+    }
+
 CSocket::~CSocket()
 /**
 	Destructor.
@@ -70,54 +85,62 @@
 	@param		aSocketType	The type of the socket.
 */
 	{
-	switch( aSocketType )
-		{
-	case EProtocolSocket:
-		{
-		if ( iCommsInfoProvider.HasConnection() )
-			{
-			// Open a protocol socket with a RConnection
-			User::LeaveIfError(iSocket.Open(
-										   iCommsInfoProvider.SocketServer(),
-										   iCommsInfoProvider.ProtocolDescription().iAddrFamily, 
-										   iCommsInfoProvider.ProtocolDescription().iSockType, 
-										   iCommsInfoProvider.ProtocolDescription().iProtocol,
-										   iCommsInfoProvider.Connection()
-										   ));				
-			}
-		else
-			{
-			// Open a protocol socket without a RConnection, we don't need one ( Loopback address )
-			User::LeaveIfError(iSocket.Open(
-										   iCommsInfoProvider.SocketServer(),
-										   iCommsInfoProvider.ProtocolDescription().iAddrFamily, 
-										   iCommsInfoProvider.ProtocolDescription().iSockType, 
-										   iCommsInfoProvider.ProtocolDescription().iProtocol
-										   ));											
-			}
-		} break;
-	case EBlankSocket:
-		{
-		// Open a blank socket
-		User::LeaveIfError(iSocket.Open(iCommsInfoProvider.SocketServer()));
-		} break;
-	default:
-		User::Invariant();
-		}
-	TInt id = iCommsInfoProvider.SessionId();
-	if(id>=0) 
-		{
-		// set socket option
-		iSocket.SetOpt(KSOHttpSessionId, KSOLHttpSessionInfo, id);
-		iSocket.SetOpt(KSoTcpKeepAlive, KSolInetTcp, KTcpTriggeredKeepAlive);
-		}
-	if(aSocketType != EBlankSocket)
-	    {
-	    iSocket.SetOpt(KSoTcpNoDelay,KSolInetTcp,1);  // Disable the nagle.
-        iSocket.SetOpt(KSORecvBuf, KSOLSocket, KSocketRecvBufSize); // Set the socket recv buf to be 16K
-	    }
+    User::LeaveIfError(Construct(aSocketType));
 	}
 
+TInt CSocket::Construct(TSocketType aSocketType)
+    {
+    TInt error = KErrNone;
+    switch( aSocketType )
+        {
+    case EProtocolSocket:
+        {
+        if ( iCommsInfoProvider.HasConnection() )
+            {
+            // Open a protocol socket with a RConnection
+            error = iSocket.Open(iCommsInfoProvider.SocketServer(),
+                                 iCommsInfoProvider.ProtocolDescription().iAddrFamily, 
+                                 iCommsInfoProvider.ProtocolDescription().iSockType, 
+                                 iCommsInfoProvider.ProtocolDescription().iProtocol,
+                                 iCommsInfoProvider.Connection()
+                                 );              
+            }
+        else
+            {
+            // Open a protocol socket without a RConnection, we don't need one ( Loopback address )
+            error = iSocket.Open(iCommsInfoProvider.SocketServer(),
+                                 iCommsInfoProvider.ProtocolDescription().iAddrFamily, 
+                                 iCommsInfoProvider.ProtocolDescription().iSockType, 
+                                 iCommsInfoProvider.ProtocolDescription().iProtocol
+                                 );                                          
+            }
+        } break;
+    case EBlankSocket:
+        {
+        // Open a blank socket
+        error = iSocket.Open(iCommsInfoProvider.SocketServer());
+        } break;
+    default:
+        User::Invariant();
+        }
+    if(error == KErrNone)
+        {
+        TInt id = iCommsInfoProvider.SessionId();
+        if(id>=0) 
+            {
+            // set socket option
+            iSocket.SetOpt(KSOHttpSessionId, KSOLHttpSessionInfo, id);
+            iSocket.SetOpt(KSoTcpKeepAlive, KSolInetTcp, KTcpTriggeredKeepAlive);
+            }
+        if(aSocketType != EBlankSocket)
+            {
+            iSocket.SetOpt(KSoTcpNoDelay,KSolInetTcp,1);  // Disable the nagle.
+            iSocket.SetOpt(KSORecvBuf, KSOLSocket, KSocketRecvBufSize); // Set the socket recv buf to be 16K
+            }
+        }
+    return error;
+    }
+
 TInt CSocket::Listen(TUint aQSize, TUint16 aPort)
 /**	
 	Start the listen service. The socket is bound to the local port specified by