datacommsserver/esockserver/csock/CS_CLI.CPP
changeset 0 dfb7c4ff071f
child 4 928ed51ddc43
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <es_ver.h>
       
    17 #include "CS_STD.H"
       
    18 #include "es_flog.h"
       
    19 #include <rsshared.h>
       
    20 
       
    21 #include <comms-infras/esockdebugmessages.h>
       
    22 
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include <es_sock_internal.h>
       
    25 #endif
       
    26 
       
    27 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
    28 #include <comms-infras/trbuf.h>
       
    29 #endif
       
    30 
       
    31 #if defined(_DEBUG) && !defined(__ESOCK_SUPPRESS_ESOCK_HANDLE_OVERWRITE_PANICS)
       
    32 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    33 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    34 _LIT(KSpecAssert_ESockCSockCS_CLI, "ESockCSockCS_CLI");
       
    35 #endif
       
    36 
       
    37 
       
    38 #if defined (__FLOG_ACTIVE)
       
    39 
       
    40 	/**
       
    41 	@internalComponent
       
    42 	*/
       
    43 	struct TNo2NameMap
       
    44 		{
       
    45 		TUint iNumber;
       
    46 		const char* iName;
       
    47 		};
       
    48 	/**
       
    49 	they must be sorted by number!
       
    50 
       
    51 	@internalComponent
       
    52 	*/
       
    53 	LOCAL_D const TNo2NameMap KAddrFamMap[] =
       
    54 		{
       
    55 			{ 0x0010, "smsprot" },
       
    56 			{ 0x0011, "wapprot" },
       
    57 			{ 0x0100, "irda"    },
       
    58 			{ 0x0101, "bt"      },
       
    59 			{ 0x0111, "plp"     },
       
    60 			{ 0x0800, "tcpip"   },
       
    61 			{ 0x0801, "ipsec6"  },
       
    62 			{ 0x0803, "eaysymb" },
       
    63 			{ 0x0806, "tcpip6"  },
       
    64 			{ 0x08b5, "mip6"    }
       
    65 		};
       
    66 
       
    67 	/**
       
    68 	@internalComponent
       
    69 	*/
       
    70 	#define NO2NAME(table,no) (MapNo2Name(table, sizeof(table)/sizeof(table[0]), no))
       
    71 
       
    72 	/**
       
    73 	do a binary search through the mapping table and return the
       
    74 	name, if found.
       
    75 
       
    76 	@internalComponent
       
    77 	*/
       
    78 	LOCAL_C const char* MapNo2Name(const TNo2NameMap* aMapping, TInt aSize, TUint aNumber)
       
    79 	{
       
    80 		TInt min = -1;
       
    81 		TInt max = aSize;
       
    82 		TInt median = 0;
       
    83 
       
    84 		TBool found = EFalse;
       
    85 		while(!found)
       
    86 			{
       
    87 			median = (max + min) / 2;
       
    88 
       
    89 			if(aNumber > aMapping[median].iNumber)
       
    90 				min = median;
       
    91 			else if(aNumber < aMapping[median].iNumber)
       
    92 				max = median;
       
    93 			else
       
    94 				found = ETrue;
       
    95 
       
    96 			// to avoid forever loops
       
    97 			if(median == ((max + min) / 2))
       
    98 				break;
       
    99 			if(min==max)
       
   100 				break;
       
   101 			}
       
   102 
       
   103 		if(found)
       
   104 			return aMapping[median].iName;
       
   105 		else
       
   106 			return "???";
       
   107 		}
       
   108 
       
   109 	/**
       
   110 	@internalComponent
       
   111 	*/
       
   112 	LOCAL_D const char* const KSockTypeMap[5] =
       
   113 		{
       
   114 		"NULL",      // 0
       
   115 		"stream",    // 1
       
   116 		"datagram",  // 2
       
   117 		"seqpacket", // 3
       
   118 		"raw"        // 4
       
   119 		};
       
   120 
       
   121 	/**
       
   122 	@internalComponent
       
   123 	*/
       
   124 	LOCAL_C const char* GetSockTypeMap(TUint aSockType)
       
   125 		{
       
   126 		return ( aSockType < sizeof(KSockTypeMap)/sizeof(KSockTypeMap[0]))
       
   127 			?
       
   128 			KSockTypeMap[aSockType]
       
   129 			:
       
   130 		"???";
       
   131 		}
       
   132 
       
   133 	/**
       
   134 	they must be sorted by number!
       
   135 
       
   136 	@internalComponent
       
   137 	*/
       
   138 	LOCAL_D const TNo2NameMap KProtocolMap[] =
       
   139 		{
       
   140 			{ 1,  "ICMP" },
       
   141 			{ 4,  "IPv4" },
       
   142 			{ 6,  "TCP"  },
       
   143 			{ 17, "UDP"  },
       
   144 			{ 41, "IPv6" },
       
   145 			{ 50, "ESP"  },
       
   146 			{ 51, "AH"   },
       
   147 			{ 0x0101, "PROT_KEY"  }, // temp assignment
       
   148 			{ 0x0103, "INET_HOOK" }, // temp assignment
       
   149 			{ 0x0f01, "INET6_RES" }  // temp assignment (tcpip6\inc\res.h)
       
   150 		};
       
   151 #endif
       
   152 
       
   153 
       
   154 EXPORT_C RSocketServ::RSocketServ()
       
   155 /**
       
   156 Default Constructor
       
   157 */
       
   158     {
       
   159     }
       
   160 
       
   161 EXPORT_C TInt RSocketServ::Connect(TUint aMessageSlots /* =8 */)
       
   162 /** Opens a session to the socket server.
       
   163 
       
   164 The number of message slots indicates how many asychronous operations are 
       
   165 allowed to be uncompleted at any one time by the combined resources opened 
       
   166 on the session. The result of having too few slots is not fatal. However, 
       
   167 operations may return KErrServerBusy indicating that no message slot was 
       
   168 available after a small time trying.
       
   169 
       
   170 RHandleBase::Close() should be called once the session is no longer required. 
       
   171 All resources which are opened using the session will be automatically closed 
       
   172 when the session terminates.
       
   173 
       
   174 When the last session which has open resources for a protocol is closed a 
       
   175 protocol module will be unloaded automatically by the socket server.
       
   176 
       
   177 @param aMessageSlots The number of message slots required. If not specified, 8.
       
   178 @return KErrNone if successful, otherwise another of the system-wide error 
       
   179 codes. */
       
   180 	{
       
   181 	LOG( ESockLog::Printf(_L8("RSocketServ %08x:\tConnect() tid %d"), this, (TUint)RThread().Id() ));
       
   182 #ifndef __ESOCK_SUPPRESS_ESOCK_HANDLE_OVERWRITE_PANICS
       
   183 	__ASSERT_DEBUG(Handle() == 0, User::Panic(KSpecAssert_ESockCSockCS_CLI, 1));
       
   184 #endif
       
   185 	
       
   186 	TSessionPref pref;
       
   187 	TInt r = Connect(pref, aMessageSlots);
       
   188 
       
   189    // Because ESock is now loaded by the Comms Root Server which is generally started during
       
   190 	// the boot this should commonly succeed; however for test code this is still a possibility
       
   191 	// Hence here we try starting it; this is an atomic operation (and cheap if it's already started)
       
   192 	if (r==KErrNotFound)
       
   193 		{
       
   194 		r=StartC32();
       
   195 		if (r==KErrNone || r==KErrAlreadyExists)
       
   196 			{
       
   197 			r = Connect(pref, aMessageSlots);
       
   198 			}
       
   199 		}
       
   200 
       
   201 	return(r);
       
   202 	}
       
   203 
       
   204 
       
   205 /**
       
   206 Default Constructor, makes sure that member data doesn't contain unnitialised values.
       
   207 */
       
   208 EXPORT_C TSessionPref::TSessionPref():
       
   209     iAddrFamily(KUndefinedAddressFamily),
       
   210     iProtocol(KUndefinedProtocol),
       
   211     iReserved(0),
       
   212     iReserved1(0),
       
   213     iReserved2(0),
       
   214     iReserved3(0),
       
   215     iReserved4(0)
       
   216     {}
       
   217 
       
   218 EXPORT_C TInt RSocketServ::Connect(const TSessionPref& aPref, TUint aMessageSlots)
       
   219 /** Opens a session to the socket server.
       
   220 
       
   221 The session prefs provides a hint to the server of which protocol the client intend to use.
       
   222 This might result in better performance for the connection.
       
   223 
       
   224 The number of message slots indicates how many asychronous operations are
       
   225 allowed to be uncompleted at any one time by the combined resources opened
       
   226 on the session. The result of having too few slots is not fatal. However,
       
   227 operations may return KErrServerBusy indicating that no message slot was
       
   228 available after a small time trying.
       
   229 
       
   230 RHandleBase::Close() should be called once the session is no longer required.
       
   231 All resources which are opened using the session will be automatically closed
       
   232 when the session terminates.
       
   233 
       
   234 When the last session which has open resources for a protocol is closed a
       
   235 protocol module will be unloaded automatically by the socket server.
       
   236 
       
   237 @param aPrefs Hint for server to create most optimal connection possible.
       
   238 @param aMessageSlots The number of message slots required. If not specified, 8.
       
   239 @return KErrNone if successful, otherwise another of the system-wide error
       
   240 codes. */
       
   241 	{
       
   242 	LOG( ESockLog::Printf(_L8("RSocketServ %08x:\tConnect(TSessionPref(%d,%d,%d)) tid %d"), this, aPref.iAddrFamily, aPref.iProtocol, aPref.iReserved, (TUint)RThread().Id() ));
       
   243 #ifndef __ESOCK_SUPPRESS_ESOCK_HANDLE_OVERWRITE_PANICS
       
   244 	__ASSERT_DEBUG(Handle() == 0, User::Panic(KSpecAssert_ESockCSockCS_CLI, 2));
       
   245 #endif
       
   246 	TInt err = CreateSession(SOCKET_SERVER_NAME, TVersion(), aMessageSlots);
       
   247 	if(err == KErrNone)
       
   248 		{
       
   249 		// Now we request the optimal server and if we get one we reconnect to that one.
       
   250 		TServerName prefServerName;
       
   251 		TPckg<TSessionPref> prefDesc(aPref);
       
   252 		err = SendReceive(ESSRequestOptimalDealer, TIpcArgs(&prefDesc, &prefServerName));
       
   253 		if(err == KErrNone && prefServerName.Length() > 0)
       
   254 			{
       
   255 			RSocketServ oldSess = *this;
       
   256 			SetHandle(0);
       
   257 			err = CreateSession(prefServerName, TVersion(), aMessageSlots);
       
   258 			oldSess.Close();
       
   259 			}
       
   260 		else if (err == KErrNotFound)
       
   261 			{
       
   262 			//Well then the pit boss is the optimal dealer
       
   263 			err = KErrNone;
       
   264 			}
       
   265 		}
       
   266 	return err;
       
   267 	}
       
   268 
       
   269 EXPORT_C TInt RSocketServ::NumProtocols(TUint &aCount)
       
   270 /** Gets the number of protocols the socket server is currently aware of.
       
   271 
       
   272 The count returned can be used in conjunction with GetProtocolInfo().
       
   273 
       
   274 @param aCount The number of protocols is returned in aCount
       
   275 @return KErrNone if successful, otherwise another of the system-wide error
       
   276 codes. */
       
   277     {
       
   278 	TPtr8 n((TUint8 *)&aCount,sizeof(aCount));
       
   279     return SendReceive(ESSNumProtocols,TIpcArgs(&n));
       
   280     }
       
   281 
       
   282 EXPORT_C TInt RSocketServ::GetProtocolInfo(TUint anIndex,TProtocolDesc &aProtocol)
       
   283 //
       
   284 // Only really implemented for completeness and debugging.
       
   285 //
       
   286 /** Gets information about a specific protocol.
       
   287 
       
   288 @param anIndex Index of required protocol description. 
       
   289 @param aProtocol A protocol description type to hold protocol information. 
       
   290 @return KErrNone if successful, otherwise another of the system-wide error codes. */
       
   291     {
       
   292 	TPckg<TProtocolDesc> protDesc(aProtocol);
       
   293 	return SendReceive(ESSProtocolInfo,TIpcArgs(&protDesc,anIndex));
       
   294     }
       
   295 
       
   296 EXPORT_C TInt RSocketServ::FindProtocol(const TProtocolName& aName,TProtocolDesc &aProtocol)
       
   297 /** Gets information about a specific protocol, identified by it's name.
       
   298 
       
   299 There is no wildcard support.
       
   300 
       
   301 @param aName Typed descriptor which identifies a protocol name. 
       
   302 @param aProtocol A protocol description type to hold protocol information. 
       
   303 @return KErrNone if successful, otherwise another of the system-wide error 
       
   304 codes. */
       
   305     {
       
   306 	TPckg<TProtocolDesc> protDesc(aProtocol);
       
   307 	return SendReceive(ESSProtocolInfoByName,TIpcArgs(&protDesc,&aName));
       
   308     }
       
   309 
       
   310 EXPORT_C void RSocketServ::StartProtocol(TUint anAddrFamily,TUint aSockType,TUint aProtocol,TRequestStatus &aStatus)
       
   311 //
       
   312 // Effectively makes all the lengthy parts of Open asynchronous.
       
   313 //
       
   314 /** Loads a specified protocol asynchronously.
       
   315 
       
   316 The protocol is specified by family, socket type and protocol identifier. 
       
   317 
       
   318 Note that client programs do not normally need to call this 
       
   319 function, as loading of a protocol is done automatically by the Sockets Server 
       
   320 when a socket of that protocol is opened. Some applications may, however, need 
       
   321 to ensure that an open socket call will not take a significant amount of time 
       
   322 (e.g. IrCOMM). This function can be called by such applications to preload the 
       
   323 protocol. 
       
   324 
       
   325 There is no way to cancel this operation once it has been called. 
       
   326 
       
   327 @param anAddrFamily Integer which identifies a protocol suite.
       
   328 @param aSockType Integer which identifies a type of socket.
       
   329 @param aProtocol Integer which identifies a specific protocol in a family.
       
   330 @param aStatus On completion will contain an error code: see the system-wide error codes. 
       
   331 
       
   332 @capability NetworkControl Protocol starting is a critical operation in the comms process and must be restricted
       
   333 */
       
   334 	{
       
   335 	LOG( ESockLog::Printf(_L8("StartProtocol: client %d [addrfam=0x%04x,socktype=%d,prot=%d]"), (TUint)RThread().Id(), anAddrFamily, aSockType, aProtocol));
       
   336 	SendReceive(ESSProtocolStart,TIpcArgs(anAddrFamily,aSockType,aProtocol),aStatus);
       
   337 	}
       
   338 
       
   339 EXPORT_C void RSocketServ::StopProtocol(TUint anAddrFamily,TUint aSockType,TUint aProtocol,TRequestStatus& aStatus)
       
   340 /**
       
   341 Unload a protocol asynchronously - note it will fail if there are any resources open
       
   342 
       
   343 @param anAddrFamily Integer which identifies a protocol suite
       
   344 @param aSockType Integer which identifies a type of socket
       
   345 @param aProtocol Integer which identifies a specific protocol in a family
       
   346 @param aStatus On completion, will contain a system-wide error codes
       
   347 
       
   348 @capability NetworkControl Protocol stopping is a critical operation in the comms process and must be restricted
       
   349 */
       
   350     {
       
   351 	LOG(ESockLog::Printf(_L8("StopProtocol: client %d [addrfam=0x%04x,socktype=%d,prot=%d]"), (TUint)RThread().Id(), anAddrFamily, aSockType, aProtocol));
       
   352 	SendReceive(ESSProtocolStop,TIpcArgs(anAddrFamily,aSockType,aProtocol),aStatus);
       
   353     }
       
   354 
       
   355 EXPORT_C void RSocketServ::SetExclusiveMode(TRequestStatus& aStatus)
       
   356 /**
       
   357 Set this session as the socket server exclusive session.
       
   358 PLEASE NOTE: This API is currently unsupported, calling it will always return KErrNone but without actually doing anything.
       
   359 
       
   360 @param aStatus On completion, will contain a system-wide error codes
       
   361 
       
   362 @capability NetworkControl Restricting Esock to one session is very dangerous and must be highly restricted
       
   363 */
       
   364     {
       
   365 	SendReceive(ESSExclusiveMode,TIpcArgs(),aStatus);
       
   366     }
       
   367 
       
   368 EXPORT_C void RSocketServ::ClearExclusiveMode()
       
   369 /**
       
   370 Clear exclusive mode for this session
       
   371 PLEASE NOTE: This API is currently unsupported, calling it will always return KErrNone but without actually doing anything.
       
   372 */
       
   373     {
       
   374 	SendReceive(ESSClearExclusiveMode,TIpcArgs());
       
   375     }
       
   376 
       
   377 EXPORT_C TInt RSocketServ::InstallExtension(const TDesC& aDllName, const TDesC& aArgs)
       
   378 /**
       
   379 Install an Esock Extension.
       
   380 PLEASE NOTE: This API is currently unsupported, calling it will always return KErrNotSupported.
       
   381 
       
   382 @param aDllName DllName for Esock Extension
       
   383 @param aArgs argument for Esock Extension
       
   384 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   385 
       
   386 @capability NetworkControl Loading extensions to Esock will be behavioural changing and must be restricted to privileged apps
       
   387 
       
   388 @deprecated Because it always return KErrNotSupported thus useless
       
   389 */
       
   390     {
       
   391 		return  (aArgs.Length())
       
   392 			?SendReceive(ESSInstallExtension,TIpcArgs(&aDllName,&aArgs,aArgs.Length()))
       
   393 			: SendReceive(ESSInstallExtension,TIpcArgs(&aDllName,(TAny*)NULL,(TAny*)NULL));
       
   394     }
       
   395 
       
   396 EXPORT_C TVersion RSocketServ::Version(void) const
       
   397 /** Gets the version number of this client.
       
   398 	
       
   399 @return Client side version number */
       
   400 	{
       
   401 
       
   402 	return(TVersion(KES32MajorVersionNumber,KES32MinorVersionNumber,KES32BuildVersionNumber));
       
   403 	}
       
   404 
       
   405 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
   406 EXPORT_C TInt RSocketServ::__DbgMarkHeap()
       
   407 /**
       
   408 Set a heap mark in the socket server
       
   409 
       
   410 Marks the start of checking the current thread's heap.
       
   411 
       
   412 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes. In release builds, KErrNone always.
       
   413 */
       
   414 	{
       
   415 	return SendReceive(ESSDbgMarkHeap,TIpcArgs());
       
   416 	}
       
   417 
       
   418 EXPORT_C TInt RSocketServ::__DbgCheckHeap(TInt aCount)
       
   419 /**
       
   420 Checks that the number of allocated cells on the current thread's heap is the same as the specified value
       
   421 
       
   422 @param aCount In debug builds, the number of heap cells expected to be allocated.
       
   423 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   424 */
       
   425 	{
       
   426 	return SendReceive(ESSDbgCheckHeap,TIpcArgs(aCount));//check if it's right 
       
   427 	}
       
   428 
       
   429 EXPORT_C TInt RSocketServ::__DbgMarkEnd(TInt aCount)
       
   430 /**
       
   431 Set a heap mark in the socket server
       
   432 
       
   433 Marks the end of checking the current thread's heap
       
   434 
       
   435 @param aCount In debug builds, the number of heap cells expected to be allocated.
       
   436 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   437 */
       
   438 	{
       
   439 	return SendReceive(ESSDbgMarkEnd,TIpcArgs(aCount));//check if it's right 
       
   440 	}
       
   441 
       
   442 EXPORT_C TInt RSocketServ::__DbgFailNext(TInt aCount)
       
   443 /**
       
   444 Set a heap mark in the socket server
       
   445 
       
   446 Simulates heap allocation failure.
       
   447 
       
   448 @param aCount In debug builds, the number of heap cells expected to be allocated.
       
   449 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   450 */
       
   451 	{
       
   452 	return SendReceive(ESSDbgFailNext,TIpcArgs(aCount));//check if it's right 
       
   453 	}
       
   454 	
       
   455 EXPORT_C TBool RSocketServ::__DbgCheckFailNext() const
       
   456 /**
       
   457 Check whether a simulated OOM fail-next set via __DbgFailNext() is still active, generally indicates that some code
       
   458 under test hasn't explored all allocation points
       
   459  
       
   460 @return EFalse if any ESOCK server heap has left FailNext simulation mode
       
   461 */
       
   462     {
       
   463 	return SendReceive(ESSDbgCheckFailNext);
       
   464 	}
       
   465 
       
   466 EXPORT_C TInt RSocketServ::__DbgFailNextMbuf(TInt aCount)
       
   467 /**
       
   468 Set a Mbuf mark in the socket server
       
   469 
       
   470 Simulates Mbuf allocation failure.
       
   471 
       
   472 @param aCount In debug builds, the number of heap cells expected to be allocated.
       
   473 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   474 */
       
   475 	{
       
   476 	return SendReceive(ESSDbgFailNextMbuf,TIpcArgs(aCount));//check if it's right 
       
   477 	}
       
   478 
       
   479 EXPORT_C TInt RSocketServ::__DbgSetMbufPoolLimit(TInt aSize)
       
   480 /**
       
   481 Set the Mbuf pool limit
       
   482 
       
   483 @param aSize indiactes the limit of MBuf pool.
       
   484 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   485 */
       
   486 	{
       
   487 	return SendReceive(ESSDbgSetMbufPoolLimit,TIpcArgs(aSize));//check if it's right 
       
   488 	}
       
   489 
       
   490 EXPORT_C TInt RSocketServ::__DbgCheckMbuf(TInt aSize)
       
   491 /**
       
   492 Checks that the number of allocated cells on the current thread's MBuf is the same as the specified value
       
   493 
       
   494 @param aSize indiactes the limit of MBuf pool.
       
   495 @return In debug builds, KErrNone, if successful, otherwise one of the other system wide error codes
       
   496 */
       
   497 	{
       
   498 	return SendReceive(ESSDbgCheckMbuf,TIpcArgs(aSize));//check if it's right 
       
   499 	}
       
   500 
       
   501 EXPORT_C TInt RSocketServ::__DbgMbufFreeSpace()
       
   502 /**
       
   503 Get the amount of free space in the MBuf manager
       
   504 
       
   505 @return free space in the MBuf manager
       
   506 */
       
   507 	{
       
   508 	TPckgBuf<TInt> i;
       
   509 	TInt result=SendReceive(ESSDbgMbufFreeSpace,TIpcArgs(&i));
       
   510 	if (KErrNone == result)
       
   511 		return i();
       
   512 	else
       
   513 		return -1;
       
   514 	}
       
   515 
       
   516 EXPORT_C TInt RSocketServ::__DbgMbufTotalSpace()
       
   517 /**
       
   518 Get the amount of total space  available in the MBuf manager
       
   519 
       
   520 @return total space  available in the MBuf manager
       
   521 */
       
   522 	{
       
   523 	TPckgBuf<TInt> i;
       
   524 	TInt result = SendReceive(ESSDbgMbufTotalSpace,TIpcArgs(&i));
       
   525 	if (KErrNone == result)
       
   526 		return i();
       
   527 	else
       
   528 		return -1;
       
   529 	}
       
   530 
       
   531 EXPORT_C TInt RSocketServ::__DbgControl(const ESockDebug::TControlMsg& aRequestMsg)
       
   532 /**
       
   533 General purpose control message for esock debug
       
   534 
       
   535 @return 
       
   536 */
       
   537 	{
       
   538 	Elements::TRBuf8* requestMsgBuffer = Elements::TRBuf8::New(aRequestMsg.Length());
       
   539 	aRequestMsg.Store(*requestMsgBuffer);
       
   540 
       
   541 	TPckgBuf<TInt> i;
       
   542 	TInt result=SendReceive(ESSDbgControl, TIpcArgs(&i, requestMsgBuffer));
       
   543 	if (KErrNone == result)
       
   544 		return i();
       
   545 	else
       
   546 		return -1;
       
   547 	}
       
   548 
       
   549 #else
       
   550 EXPORT_C TInt RSocketServ::__DbgMarkHeap()
       
   551 /**
       
   552 Set a heap mark in the socket server
       
   553 */
       
   554 	{
       
   555    return KErrNone;
       
   556 	}
       
   557 
       
   558 EXPORT_C TInt RSocketServ::__DbgCheckHeap(TInt /*aCount*/)
       
   559 /**
       
   560 Set a heap mark in the socket server
       
   561 */
       
   562 	{
       
   563    return KErrNone;
       
   564 	}
       
   565 
       
   566 EXPORT_C TInt RSocketServ::__DbgMarkEnd(TInt /*aCount*/)
       
   567 /**
       
   568 Set a heap mark in the socket server
       
   569 */
       
   570 	{
       
   571    return KErrNone;
       
   572 	}
       
   573 
       
   574 EXPORT_C TInt RSocketServ::__DbgFailNext(TInt /*aCount*/)
       
   575 /**
       
   576 Set a heap mark in the socket server
       
   577 */
       
   578 	{
       
   579    return KErrNone;
       
   580 	}
       
   581 
       
   582 EXPORT_C TBool RSocketServ::__DbgCheckFailNext() const
       
   583 /**
       
   584 Empty release implementation
       
   585 */
       
   586     {
       
   587     return KErrNone;
       
   588 	}
       
   589 	
       
   590 EXPORT_C TInt RSocketServ::__DbgFailNextMbuf(TInt /*aCount*/)
       
   591 /**
       
   592 Set a Mbuf mark in the socket server
       
   593 */
       
   594    {
       
   595    return KErrNone;
       
   596 	}
       
   597 
       
   598 EXPORT_C TInt RSocketServ::__DbgSetMbufPoolLimit(TInt /*aSize*/)
       
   599 /**
       
   600 Set the Mbuf pool limit
       
   601 */
       
   602    {
       
   603    return KErrNone;
       
   604 	}
       
   605 
       
   606 EXPORT_C TInt RSocketServ::__DbgCheckMbuf(TInt /*aSize*/)
       
   607 /**
       
   608 Set the Mbuf pool limit
       
   609 */
       
   610    {
       
   611    return KErrNone;
       
   612 	}
       
   613 
       
   614 EXPORT_C TInt RSocketServ::__DbgMbufFreeSpace()
       
   615 /**
       
   616 Get the amount of free space in the MBuf manager
       
   617 */
       
   618    {
       
   619    return KErrNone;
       
   620 	}
       
   621 
       
   622 EXPORT_C TInt RSocketServ::__DbgMbufTotalSpace()
       
   623 /**
       
   624 Get the amount of free space in the MBuf manager
       
   625 */
       
   626    {
       
   627    return KErrNone;
       
   628 	}
       
   629 
       
   630 EXPORT_C TInt RSocketServ::__DbgControl(const ESockDebug::TControlMsg& /*aRequestMsg*/)
       
   631 /**
       
   632 General purpose control message for esock debug, self dispatching messages to be thrown over it
       
   633 
       
   634 @return 
       
   635 */
       
   636 	{
       
   637 	return KErrNone;
       
   638 	}
       
   639 
       
   640 #endif // _DEBUG
       
   641 
       
   642 EXPORT_C RSocket::RSocket()
       
   643 /**
       
   644 Default Constructor
       
   645 */
       
   646 	{
       
   647 	}
       
   648 
       
   649 EXPORT_C TInt RSocket::Open(RSocketServ &aServer,TUint anAddrFamily,TUint aSockType,TUint aProtocol)
       
   650 /** Opens an implicit socket by creating a new subsession to the socket server. Implicit socket is not explicitly associated
       
   651 with any connection. The socket will choose the default connection for sending the packets. 
       
   652 
       
   653 Implicit socket accepts packets routed through any connection.
       
   654 
       
   655 
       
   656 Opens a channel to a protocol identified by a tuple of constants. If a socket 
       
   657 is the first to be opened for a protocol it will have the additional effect 
       
   658 of loading the protocol in the socket server.
       
   659 
       
   660 NOTE: Deprecated default connection scenario.
       
   661 Applications exercising the default connection scenario must (from 9.3 onwards) switch to explicit 
       
   662 connection scenario. 
       
   663 - The default connection scenario is where an application holding one started RConnection opens a socket 
       
   664   without explicitly associating it with the RConnection. The explicit association can be made by passing 
       
   665   the RConnection or a derived RSubConnection to an appropriate overload of RSocket::Open(...) 
       
   666   (not this method). 
       
   667 - The implicit connection scenario is where an application holding either none or many started 
       
   668   RConnections (to different access points) opens a socket without explicitly associating it an RConnection.
       
   669 - The explicit connection scenario is where an application holding started RConnections opens a 
       
   670   socket explicitly associating it with one of its RConnections.
       
   671 
       
   672 Applications attempting to exercise the default connection scenario shall (from 9.3 onwards) 
       
   673 receive an error from RSocket::Open(...). The actual error code is yet to be defined.
       
   674 
       
   675 @param aServer The socket server session.
       
   676 @param anAddrFamily A valid address constant for a protocol family.
       
   677 @param aSockType A valid socket type for the protocol.
       
   678 @param aProtocol A protocol constant which identifies a specific protocol. 
       
   679 @return KErrNone if successful, otherwise another of the system-wide error codes
       
   680 
       
   681 @capability Dependent Capability required depends on the type of socket so deferred to PRT
       
   682 */
       
   683     {
       
   684 	RSessionBase &s=aServer;
       
   685 
       
   686 	const TInt ret = CreateSubSession(s,ESoCreate,TIpcArgs(anAddrFamily,aSockType,aProtocol));
       
   687 
       
   688 	LOG( ESockLog::Printf(_L8("RSocket %08x:\tOpen(addrfam=%s(0x%04x), socktype=%s(%d), prot=%s(%d)): tid %d, ret=%d]"),
       
   689 		this, NO2NAME(KAddrFamMap, anAddrFamily), anAddrFamily,
       
   690 		GetSockTypeMap(aSockType), aSockType,
       
   691 		NO2NAME(KProtocolMap, aProtocol), aProtocol,
       
   692 		(TUint)RThread().Id(), ret));
       
   693 
       
   694 	return ret;
       
   695 	}
       
   696 
       
   697 EXPORT_C TInt RSocket::Open(RSocketServ &aServer,const TDesC& aName)
       
   698 /** Opens an implicit socket by creating a new subsession to the socket server. Implicit socket is not explicitly associated
       
   699 with any connection. The socket will choose the default connection for sending the packets. 
       
   700 
       
   701 Implicit socket accepts packets routed through any connection.
       
   702 
       
   703 Opens a channel to a protocol identified by a name. If a socket is the 
       
   704 first to be opened for a protocol it will have the additional effect of loading 
       
   705 the protocol in the socket server.
       
   706 
       
   707 NOTE: Deprecated default connection scenario.
       
   708 Applications exercising the default connection scenario must (from 9.3 onwards) switch to explicit 
       
   709 connection scenario. 
       
   710 - The default connection scenario is where an application holding one started RConnection opens a socket 
       
   711   without explicitly associating it with the RConnection. The explicit association can be made by passing 
       
   712   the RConnection or a derived RSubConnection to an appropriate overload of RSocket::Open(...) 
       
   713   (not this method). 
       
   714 - The implicit connection scenario is where an application holding either none or many started 
       
   715   RConnections (to different access points) opens a socket without explicitly associating it an RConnection.
       
   716 - The explicit connection scenario is where an application holding started RConnections opens a 
       
   717   socket explicitly associating it with one of its RConnections.
       
   718 
       
   719 Applications attempting to exercise the default connection scenario shall (from 9.3 onwards) 
       
   720 receive an error from RSocket::Open(...). The actual error code is yet to be defined.
       
   721 
       
   722 @param aServer The socket server session.
       
   723 @param aName Name of a protocol.
       
   724 @return KErrNone if successful, otherwise another of the system-wide error codes. 
       
   725 
       
   726 @capability Dependent Capability required depends on the type of socket so deferred to PRT
       
   727 */
       
   728 	{
       
   729 	LOG(TBuf8<64> buf8);
       
   730 	LOG(buf8.Copy(aName));
       
   731 	LOG(ESockLog::Printf(_L8("RSocket %08x:\tOpen(name=%S) tid %d"), this, &buf8, (TUint)RThread().Id() ));
       
   732 	if ((aName.Locate(KMatchAny)!=KErrNotFound) || (aName.Locate(KMatchOne)!=KErrNotFound))
       
   733 		return KErrBadName;
       
   734 	TProtocolDesc d;
       
   735 	TInt r=aServer.FindProtocol(aName,d);
       
   736 	if (r!=KErrNone)
       
   737 		return r;
       
   738 	return Open(aServer,d.iAddrFamily,d.iSockType,d.iProtocol);
       
   739 	}
       
   740 
       
   741 EXPORT_C TInt RSocket::Open(RSocketServ &aServer)
       
   742 /**Opens an implicit socket by creating a new subsession to the socket server. Implicit socket is not explicitly associated
       
   743 with any connection. The socket will choose the default connection for sending the packets. 
       
   744 
       
   745 Implicit socket accepts packets routed through any connection.
       
   746 
       
   747 
       
   748 Provides a blank channel to the socket server which has no protocol 
       
   749 associated. A socket opened in this manner is suitable as an argument to Accept(), 
       
   750 which will marry the blank socket to a protocol when a connection is established 
       
   751 to a remote endpoint.
       
   752 
       
   753 @param aServer The socket server session.
       
   754 @return KErrNone if successful, otherwise another of the system-wide error 
       
   755 codes.
       
   756 
       
   757 @capability Dependent Capability required depends on the type of socket so deferred to PRT
       
   758 */
       
   759     {
       
   760 	return CreateSubSession(aServer,ESoCreateNull,TIpcArgs());
       
   761 	}
       
   762 
       
   763 EXPORT_C TInt RSocket::Open(RSocketServ &aServer,TUint anAddrFamily,TUint aSockType,TUint aProtocol,RConnection& aConnection)
       
   764 /**Opens an explicit socket by creating a new subsession to the socket server. The socket is explicitly associated with the
       
   765 same underlying connection as an existing RConnection instance.
       
   766 
       
   767 Socket traffic is directed to and from the specified connection only.
       
   768 
       
   769 
       
   770 @note The association is instantaneous, in that the socket is associated with the
       
   771 interface that the RConnection is associated with at the present time.  This association
       
   772 terminates when the underlying interface goes down.
       
   773 
       
   774 @released since 7.0S
       
   775 
       
   776 @param aServer The socket server session.
       
   777 @param anAddrFamily A valid address constant for a protocol family.
       
   778 @param aSockType A valid socket type for the protocol.
       
   779 @param aProtocol A protocol constant which identifies a specific protocol.
       
   780 @param aConnection Existing RConnection whose interface this socket will be associated with.
       
   781 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   782 
       
   783 @capability Dependent Capability required depends on the type of connection so deferred to PRT
       
   784 
       
   785  */
       
   786     {
       
   787 	// passing an RConnection which doesn't belong to the same session is a serious programming error, hence panic.
       
   788 	if (!aConnection.SameSession(aServer.Handle()))
       
   789 		Panic(EBadRConnection);
       
   790 
       
   791 	TSockOpenBufC openArgPkg;
       
   792 	openArgPkg.iArgs.iAddrFamily = anAddrFamily;
       
   793 	openArgPkg.iArgs.iSockType = aSockType;
       
   794 	openArgPkg.iArgs.iProtocol = aProtocol;
       
   795 	openArgPkg.iArgs.iHandle = aConnection.SubSessionHandle();
       
   796 
       
   797 	RSessionBase &s=aServer;
       
   798 	const TInt ret = CreateSubSession(s,ESoCreateWithConnection,TIpcArgs(&openArgPkg));
       
   799 
       
   800 	LOG(ESockLog::Printf(_L8("RSocket::Open(addrfam=0x%04x(%s), socktype=%d(%s), prot=%d(%s), rconn=%x): tid %d ,ret=%d"),
       
   801 		anAddrFamily, NO2NAME(KAddrFamMap, anAddrFamily),
       
   802 		aSockType, GetSockTypeMap(aSockType),
       
   803 		aProtocol, NO2NAME(KProtocolMap, aProtocol),
       
   804 		aConnection.SubSessionHandle(), (TUint)RThread().Id(), ret));
       
   805 
       
   806 	return ret;
       
   807 	}
       
   808 
       
   809 EXPORT_C TInt RSocket::Open(RSocketServ &aServer,TUint anAddrFamily,TUint aSockType,TUint aProtocol,RSubConnection& aSubConnection)
       
   810 /**Opens an explicit socket by creating a new subsession to the socket server. The socket is explicitly associated with the
       
   811 same underlying connection as an existing RSubConnection instance.
       
   812 
       
   813 Socket traffic is directed to and from the specified connection only.
       
   814 	
       
   815 
       
   816 @released since 7.0S
       
   817 
       
   818 @param aServer The socket server session.
       
   819 @param anAddrFamily A valid address constant for a protocol family.
       
   820 @param aSockType A valid socket type for the protocol.
       
   821 @param aProtocol A protocol constant which identifies a specific protocol.
       
   822 @param aSubConnection Existing RSubConnection this socket will be associated with.
       
   823 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
   824 
       
   825 @capability Dependent Capability required depends on the type of connection so deferred to PRT
       
   826 
       
   827  */
       
   828     {
       
   829 	// passing an RSubConnection which doesn't belong to the same session is a serious programming error, hence panic.
       
   830 	if (!aSubConnection.SameSession(aServer.Handle()))
       
   831 		{
       
   832 		Panic(EBadRConnection);
       
   833 		}
       
   834 
       
   835 	TSockOpenBufC openArgPkg;
       
   836 	openArgPkg.iArgs.iAddrFamily = anAddrFamily;
       
   837 	openArgPkg.iArgs.iSockType = aSockType;
       
   838 	openArgPkg.iArgs.iProtocol = aProtocol;
       
   839 	openArgPkg.iArgs.iHandle = aSubConnection.SubSessionHandle();
       
   840 
       
   841 	RSessionBase &s=aServer;
       
   842 	const TInt ret = CreateSubSession(s, ESoCreateWithSubConnection,TIpcArgs(&openArgPkg));
       
   843 
       
   844 	LOG( ESockLog::Printf(_L8("RSocket::Open(addrfam=0x%04x(%s), socktype=%d(%s), prot=%d(%s), rsubconn=%x): tid %d ,ret=%d"),
       
   845 		anAddrFamily, NO2NAME(KAddrFamMap, anAddrFamily),
       
   846 		aSockType, GetSockTypeMap(aSockType),
       
   847 		aProtocol, NO2NAME(KProtocolMap, aProtocol),
       
   848 		aSubConnection.SubSessionHandle(), (TUint)RThread().Id(), ret));
       
   849 
       
   850 	return ret;
       
   851 	}
       
   852 
       
   853 EXPORT_C void RSocket::Close()
       
   854 //
       
   855 // Blocking close
       
   856 //
       
   857 /** Closes a socket. 
       
   858 
       
   859 If a socket has been opened using Open() then it should be closed using Close(). 
       
   860 This will ensure all associated resources are released. 
       
   861 
       
   862 Closing serves two distinct purposes:
       
   863 
       
   864 To release resources associated with the IPC channel to the socket server.
       
   865 
       
   866 To disconnect a socket if it is connected.
       
   867 
       
   868 If a socket is connected, then calling close is equivalent to calling Shutdown() 
       
   869 with an argument of RSocket::ENormal, synchronously waiting for the request 
       
   870 to complete, and then closing the IPC channel. If asynchronous or alternative 
       
   871 methods of disconnecting are required then Shutdown() should be called before 
       
   872 Close().
       
   873 
       
   874 If the RSocketServ session on which a protocol was opened is closed, then 
       
   875 all sockets associated with that session will be abortively closed and any 
       
   876 further requests on the sockets will result in panics.
       
   877 
       
   878 If a protocol has the flag KSIGracefulClose in its protocol information, when 
       
   879 Close() is called on a connected socket, the socket will synchronously block 
       
   880 until a response to a close request has been received or some other protocol 
       
   881 condition causes the call to complete. */
       
   882 	{
       
   883 	LOG( ESockLog::Printf(_L8("RSocket %08x:\tClose() tid %d"), this, (TUint)RThread().Id()));
       
   884 	if (SubSessionHandle())
       
   885 		{
       
   886 		CloseSubSession(ESoClose);
       
   887 		}
       
   888 	}
       
   889 
       
   890 EXPORT_C void RSocket::Shutdown(TShutdown aHow,TRequestStatus &aStatus)
       
   891 /** Shuts down a connected socket - asynchronous.
       
   892 
       
   893 This method is asynchronous as non emergency shutdown may take a while.
       
   894 
       
   895 The shut down method allows input and output to be individually stopped for a 
       
   896 protocol endpoint. For protocols which support data-in disconnect message, 
       
   897 additional arguments are provided.
       
   898 
       
   899 Shutdown() can be used for protocols which do not have the KSIConnectionLess 
       
   900 flag in their protocol information.
       
   901 
       
   902 To use data in disconnection a protocol must have the flag KSIDisconnectData 
       
   903 in its protocol information.
       
   904 
       
   905 There is no way to cancel a socket shutdown once it has started.
       
   906 
       
   907 @param aHow Shutdown option. All variants complete when a socket is disconnected.
       
   908 If the parameter is within the range of TShutdown values, pending read and write
       
   909 operations are cancelled.  If the parameter is outside the range of TShutdown values,
       
   910 then the behaviour is as if ENormal were specified except that pending read and write
       
   911 operations are not cancelled.  Note that the behaviour of using parameters outside the
       
   912 range of TShutdown values may change in a future release and should not be relied upon.
       
   913 
       
   914 @param aStatus On return KErrNone if successful, otherwise another of the system-wide error 
       
   915 codes.
       
   916 
       
   917 @capability Dependent Capability required depends on the type of socket so deferred to PRT
       
   918 */
       
   919 	{
       
   920     SendReceive(ESoShutdown,TIpcArgs(aHow),aStatus);
       
   921 	}
       
   922 
       
   923 EXPORT_C void RSocket::Shutdown(TShutdown aHow,const TDesC8 &aDisconnectDataOut,TDes8 &aDisconnectDataIn,TRequestStatus &aStatus)
       
   924 /** 
       
   925 Shuts down a connected socket with disconnect data - asynchronous.
       
   926 
       
   927 This method is asynchronous as non emergency shutdown may take a while.
       
   928 
       
   929 The shut down method allows input and output to be individually stopped for a 
       
   930 protocol endpoint. For protocols which support data-in disconnect message, 
       
   931 additional arguments are provided.
       
   932 
       
   933 Shutdown() can be used for protocols which do not have the KSIConnectionLess 
       
   934 flag in their protocol information.
       
   935 
       
   936 To use data in disconnection a protocol must have the flag KSIConnectData 
       
   937 in its protocol information.
       
   938 
       
   939 There is no way to cancel a socket shutdown once it has started.
       
   940 
       
   941 @param aHow Shutdown option. All variants complete when a socket is disconnected.
       
   942 @param aDisconnectDataOut A descriptor containing data to be sent.
       
   943 @param aDisconnectDataIn A descriptor to receive data.
       
   944 @param aStatus On return KErrNone if successful, otherwise another of the system-wide error 
       
   945 codes.
       
   946 
       
   947 @capability Dependent Capability required depends on the type of socket so deferred to PRT
       
   948 */
       
   949 	{
       
   950     SendReceive(ESoShutdown,TIpcArgs(aHow,&aDisconnectDataOut,&aDisconnectDataIn),aStatus);
       
   951 	}
       
   952 
       
   953 EXPORT_C void RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
   954 /** Sends data to a remote host on a connected socket with options set by protocol 
       
   955 specific flags.
       
   956 
       
   957 A socket may only have one send operation in progress at any one time. Send() 
       
   958 should only be used with connected sockets. 
       
   959 	
       
   960 If a protocol's information flag is marked with KSIUrgentData, then KSockWriteUrgent 
       
   961 may be provided as a flag to Send(). All other flags are protocol specific.
       
   962 
       
   963 @param aBuffer The data to be sent.
       
   964 @param someFlags Flags which are passed through to protocol
       
   965 @param aStatus On return KErrNone if successful, otherwise another of the system-wide error 
       
   966 codes. Note that KErrEof indicates that the socket has been shutdown with option 
       
   967 EStopOutput. 
       
   968 
       
   969 @capability Dependent on the type of socket so deferred to PRT */
       
   970 	{
       
   971 	SendReceive(ESoSendNoLength,TIpcArgs(someFlags,aBuffer.Length(),&aBuffer),aStatus);
       
   972 	}
       
   973 
       
   974 EXPORT_C void RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus,TSockXfrLength &aLen)
       
   975 /** Sends data to a remote host on a connected socket with options set by protocol specific flags.
       
   976 
       
   977 The length of the descriptor indicates the amount of data to be sent. The 
       
   978 TSockXfrLength argument will return the amount of data actually sent. 
       
   979 
       
   980 A socket may only have one send operation in progress at any one time.
       
   981 
       
   982 Send() should only be used with connected sockets. 
       
   983 
       
   984 If a protocol's information flag is marked with KSIUrgentData, then KSockWriteUrgent 
       
   985 may be provided as a flag to Send(). All other flags are protocol specific.
       
   986 
       
   987 @param aBuffer The data to be sent.
       
   988 @param someFlags Flags which are passed through to protocol
       
   989 @param aStatus On return KErrNone if successful, otherwise another of the system-wide error 
       
   990 codes. Note that KErrEof indicates that the socket has been shutdown 
       
   991 with option EStopOutput
       
   992 @param aLen Filled in with amount of data sent before completion
       
   993 
       
   994 @capability Dependent Capability required depends on the type of socket so deferred to PRT */
       
   995 	{
       
   996 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
   997 	SendReceive(ESoSend,TIpcArgs(someFlags,&aLen,&aBuffer),aStatus);
       
   998 	}
       
   999 
       
  1000 
       
  1001 EXPORT_C void RSocket::Recv(TDes8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
  1002 /** Receives data from a remote host, allowing flags for protocol specific information.
       
  1003 	
       
  1004 For a stream-interfaced socket the function only completes when the full 
       
  1005 amount of requested data has been received (or the connection breaks). This 
       
  1006 means when the descriptor has been filled to its maximum length (not its current 
       
  1007 length). 
       
  1008 
       
  1009 For a datagram-interface socket, the function completes when one datagram 
       
  1010 arrives - even if it is not sufficient to fill the buffer. If the datagram 
       
  1011 does not fit in the buffer supplied then the remaining data will be lost. 
       
  1012 
       
  1013 Recv() should only be used with connected sockets. 
       
  1014 
       
  1015 A socket may only have one receive operation outstanding at any one time.
       
  1016 
       
  1017 If a protocol's information flag is marked with KSIPeekData, then KSockReadPeek 
       
  1018 may be provided as a flag to Recv(). All other flags are protocol specific.
       
  1019 
       
  1020 @param aBuffer A descriptor where data received will be placed.
       
  1021 @param someFlags Flags for protocol specific information.
       
  1022 @param aStatus On return, KErrNone if successful, otherwise another of the system-wide 
       
  1023 error codes. Note that KErrEof indicates either that a remote connection is closed, 
       
  1024 and that no more data is available for reading, or the socket has been shutdown 
       
  1025 with option RSocket::EStopInput.
       
  1026 
       
  1027 @capability Dependent on the type of socket so deferred to PRT */
       
  1028 	{
       
  1029 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)	
       
  1030 	SendReceive(ESoRecvNoLength,TIpcArgs(someFlags,aBuffer.MaxLength(),&aBuffer),aStatus);
       
  1031 	}
       
  1032 
       
  1033 EXPORT_C void RSocket::Recv(TDes8 &aBuffer,TUint someFlags,TRequestStatus &aStatus,TSockXfrLength &aLen)
       
  1034 /** Receives data from a remote host, allowing flags for protocol specific information. 
       
  1035 		
       
  1036 For a stream-interfaced sockets, the function only completes when the full 
       
  1037 amount of requested data has been received (or the connection breaks). This 
       
  1038 means when the descriptor has been filled to its maximum length (not its current 
       
  1039 length). 
       
  1040 
       
  1041 For a datagram-interface socket, the function completes when one datagram 
       
  1042 arrives - even if it is not sufficient to fill the buffer. If the datagram does not fit
       
  1043 in the buffer supplied, remaining data may be retrieved using the Datagram Continuation feature.
       
  1044 
       
  1045 This function implements the Datagram Continuation feature for PRTs implementing PRT1.5: the ability to read a datagram in parts. 
       
  1046 For a client request to read a datagram, using the TSockXfrLength parameter, remaining unread octets of the datagram 
       
  1047 are returned in the TSockXfrLength parameter.
       
  1048 The client can then read the remaining octets by further reads with the  'KSockReadContinuation' flag OR'd into the flags field. 
       
  1049 Remaining octets are discarded upon the next read without the KSockReadContinuation flag set.
       
  1050 
       
  1051 Recv() should only be used with connected sockets. 
       
  1052 
       
  1053 A socket may only have one receive operation outstanding at any one time.
       
  1054 
       
  1055 If a protocol's information flag is marked with KSIPeekData, then KSockReadPeek 
       
  1056 may be provided as a flag to Recv(). All other flags are protocol specific.
       
  1057 
       
  1058 @param aBuffer A descriptor where data received will be placed.
       
  1059 @param someFlags Flags for protocol specific information.
       
  1060 @param aStatus Reference to the request status object. On completion, KErrNone if 
       
  1061 successful, otherwise one of the system wide error codes. Note that KErrEof 
       
  1062 indicates either that a remote connection is closed, and that no more data 
       
  1063 is available for reading, or the socket has been shutdown with option RSocket::EStopInput.
       
  1064 @param aLen For non-datagram sockets, on return, a length which indicates how 
       
  1065 much data was read. This is the same as length of the returned aDesc. 
       
  1066 For datagram sockets, this parameter returns the number of remaining unread octets.
       
  1067 
       
  1068 @capability Dependent on the type of socket so deferred to PRT */
       
  1069 	{
       
  1070 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)	
       
  1071 	SendReceive(ESoRecv,TIpcArgs(someFlags,&aLen,&aBuffer),aStatus);
       
  1072 
       
  1073 	}
       
  1074 
       
  1075 EXPORT_C void RSocket::RecvOneOrMore(TDes8 &aBuffer,TUint someFlags,TRequestStatus &aStatus,TSockXfrLength &aLen)
       
  1076 /** Receives data from a remote host and completes when data is available. 
       
  1077 	
       
  1078 The function reads at least one byte of data, but will complete as soon as 
       
  1079 any data is available. The amount of data received is returned via the TSockXfrLength 
       
  1080 argument.
       
  1081 
       
  1082 RecvOneOrMore() can only be used with stream-interfaced connected sockets; 
       
  1083 datagram interface sockets will return KErrNotSupported.
       
  1084 
       
  1085 A socket may only have one receive operation outstanding at any one time.
       
  1086 
       
  1087 @param aBuffer A descriptor where data read will be placed.
       
  1088 @param someFlags Flags which are passed through to protocol.
       
  1089 @param aStatus On completion, KErrNone if successful, otherwise one of the system 
       
  1090 wide error codes. Note that KErrEof indicates either that a remote connection is 
       
  1091 closed, and that no more data is available for reading, or the socket has 
       
  1092 been shutdown with option RSocket::EStopInput.
       
  1093 @param aLen For non-datagram sockets, on return, a length which indicates how 
       
  1094 much data was read. This is the same as length of the returned aDesc. For 
       
  1095 datagram sockets, this parameter is not used.
       
  1096 
       
  1097 @capability Dependent on the type of socket so deferred to PRT */
       
  1098 	{
       
  1099 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)	
       
  1100 	SendReceive(ESoRecvOneOrMore,TIpcArgs(someFlags,&aLen,&aBuffer),aStatus);
       
  1101 	}
       
  1102 
       
  1103 EXPORT_C void RSocket::RecvOneOrMore(TDes8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
  1104 /** Receives data from a remote host and completes when data is available. 
       
  1105 	
       
  1106 The function reads at least one byte of data, but will complete as soon as 
       
  1107 any data is available. The amount of data received is returned via the TSockXfrLength 
       
  1108 argument.
       
  1109 
       
  1110 RecvOneOrMore() can only be used with stream-interfaced connected sockets; 
       
  1111 datagram interface sockets will return KErrNotSupported.
       
  1112 
       
  1113 A socket may only have one receive operation outstanding at any one time.
       
  1114 
       
  1115 @param aBuffer A descriptor where data read will be placed.
       
  1116 @param someFlags Flags which are passed through to protocol.
       
  1117 @param aStatus On completion, KErrNone if successful, otherwise one of the system 
       
  1118 wide error codes. Note that KErrEof indicates either that a remote connection is 
       
  1119 closed, and that no more data is available for reading, or the socket has 
       
  1120 been shutdown with option RSocket::EStopInput.
       
  1121 
       
  1122 @capability Dependent on the type of socket so deferred to PRT */
       
  1123 	{
       
  1124 	SendReceive(ESoRecvOneOrMoreNoLength,TIpcArgs(someFlags,aBuffer.MaxLength(),&aBuffer),aStatus);
       
  1125 	}
       
  1126 
       
  1127 EXPORT_C void RSocket::Read(TDes8 &aBuffer,TRequestStatus &aStatus)
       
  1128 /** Receives data from a remote host.
       
  1129 	
       
  1130 For a stream-interfaced sockets, the function only completes when the full 
       
  1131 amount of requested data has been received (or the connection breaks). This 
       
  1132 means when the descriptor has been filled to its maximum length (not its current 
       
  1133 length). For a connection-oriented datagram-interface, the function completes 
       
  1134 when a datagram arrives even if it is not sufficient to fill the buffer.
       
  1135 
       
  1136 Read() should only be used with connected sockets.
       
  1137 
       
  1138 A socket may only have one receive operation outstanding at any one time.
       
  1139 
       
  1140 @param aBuffer A descriptor where data read will be placed.
       
  1141 @param aStatus On completion, KErrNone if successful, otherwise one of the system 
       
  1142 wide error codes. Note that KErrEof indicates either that a remote connection is 
       
  1143 closed, and that no more data is available for reading, or the socket has 
       
  1144 been shutdown with option RSocket::EStopInput.
       
  1145 
       
  1146 @capability Dependent on the type of socket so deferred to PRT */
       
  1147 	{
       
  1148 	SendReceive(ESoRead,TIpcArgs(0,aBuffer.MaxLength(),&aBuffer),aStatus);
       
  1149 	}
       
  1150 
       
  1151 EXPORT_C void RSocket::Write(const TDesC8 &aBuffer,TRequestStatus &aStatus)
       
  1152 /** Sends data to a remote host.
       
  1153 
       
  1154 Write() should only be used with connected sockets. 
       
  1155 
       
  1156 @param aBuffer The data to be sent.
       
  1157 @param aStatus On completion, KErrNone if successful, otherwise one of the 
       
  1158 system wide error codes. Note that KErrEof indicates that the socket has been shutdown 
       
  1159 with option EStopOutput.
       
  1160 
       
  1161 @capability Dependent on the type of socket so deferred to PRT */
       
  1162 	{
       
  1163 	SendReceive(ESoWrite,TIpcArgs(0,aBuffer.Length(),&aBuffer),aStatus);
       
  1164 	}
       
  1165 
       
  1166 
       
  1167 EXPORT_C void RSocket::SendTo(const TDesC8 &aBuffer,TSockAddr &anAddr,TUint someFlags,TRequestStatus &aStatus)
       
  1168 /** Sends data to a remote host through a (possibly) unconnected socket to a specified destination 
       
  1169 address.
       
  1170 	
       
  1171 Flags are provided to add protocol specific information. The length of the 
       
  1172 descriptor indicates the amount of data to be sent. A socket may only have 
       
  1173 one send operation in progress at any one time.
       
  1174 
       
  1175 @param aBuffer The data to be sent.
       
  1176 @param anAddr A remote destination address for unconnected sends
       
  1177 @param someFlags Flags which are passed through to protocol
       
  1178 @param aStatus On completion, KErrNone if successful, otherwise one of the 
       
  1179 system wide error codes. Note that KErrEof indicates that the socket has been shutdown 
       
  1180 with option EStopOutput.
       
  1181 
       
  1182 @capability Dependent on the type of socket so deferred to PRT */
       
  1183 	{
       
  1184 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
  1185 	SendReceive(ESoSendToNoLength,TIpcArgs(someFlags,&anAddr,&aBuffer),aStatus);
       
  1186 	}
       
  1187 
       
  1188 EXPORT_C void RSocket::RecvFrom(TDes8 &aBuffer,TSockAddr &anAddr,TUint someFlags,TRequestStatus &aStatus)
       
  1189 /** Receives data from a remote host through a (possibly) unconnected socket and returns a source address.
       
  1190 
       
  1191 Flags are provided to add protocol specific information. 
       
  1192 
       
  1193 A socket may only have one receive operation outstanding at any one time.
       
  1194 
       
  1195 @param aDesc A descriptor where data read will be placed.
       
  1196 @param anAddr A remote source address for unconnected receives. Returns KAfInet6 in TSockAddr::Family() 
       
  1197 for IPv4 ICMP packets. Returns KAfInet for IPv4 TCP and UDP sockets.
       
  1198 @param flags Flags which are passed through to protocol.
       
  1199 @param aStatus On completion, KErrNone if successful, otherwise one of the system wide error codes. 
       
  1200 Note that KErrEof indicates either that a remote connection is 
       
  1201 closed, and that no more data is available for reading, or the socket has 
       
  1202 been shutdown with option RSocket::EStopInput.
       
  1203 
       
  1204 @capability Dependent on the type of socket so deferred to PRT */
       
  1205 	{
       
  1206 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)	
       
  1207 	SendReceive(ESoRecvFromNoLength,TIpcArgs(someFlags,&anAddr,&aBuffer),aStatus);
       
  1208 	}
       
  1209 
       
  1210 EXPORT_C void RSocket::SendTo(const TDesC8 &aBuffer,TSockAddr &anAddr,TUint someFlags,TRequestStatus &aStatus,TSockXfrLength &aLen)
       
  1211 /** Sends data to a remote host through a (possibly) unconnected socket to a specified destination 
       
  1212 address. 
       
  1213 
       
  1214 Flags are provided to add protocol specific information. The length 
       
  1215 of the descriptor indicates the amount of data to be sent. A socket may only 
       
  1216 have one send operation in progress at any one time. The TSockXfrLength argument 
       
  1217 will return the amount of data sent.
       
  1218 
       
  1219 @param aBuffer The data to be sent.
       
  1220 @param anAddr A remote destination address for unconnected sends
       
  1221 @param someFlags Flags which are passed through to protocol
       
  1222 @param aStatus On completion, KErrNone if successful, otherwise one of the system 
       
  1223 wide error codes. Note that KErrEof indicates that the socket has been shutdown 
       
  1224 with option EStopOutput.
       
  1225 @param aLen Filled in with amount of data sent before completion
       
  1226 
       
  1227 @capability Dependent on the type of socket so deferred to PRT */
       
  1228 	{
       
  1229 	aLen = someFlags;
       
  1230 
       
  1231 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)
       
  1232 	SendReceive(ESoSendTo,TIpcArgs(&aLen,&anAddr,&aBuffer),aStatus);
       
  1233 	}
       
  1234 
       
  1235 EXPORT_C void RSocket::RecvFrom(TDes8 &aBuffer,TSockAddr &anAddr,TUint someFlags,TRequestStatus &aStatus,TSockXfrLength &aLen)
       
  1236 /** Receives data from a remote host through a (possibly) unconnected socket where a source address 
       
  1237 is returned.
       
  1238 
       
  1239 Flags are provided to add protocol specific information. 
       
  1240 
       
  1241 A socket may only have one receive operation outstanding at any one time.
       
  1242 	
       
  1243 @param aBuffer A descriptor where data read will be placed
       
  1244 @param anAddr A remote source address for unconnected receives. Returns KAfInet6 in TSockAddr::Family() 
       
  1245 for IPv4 ICMP packets. Returns KAfInet for IPv4 TCP and UDP sockets.
       
  1246 @param someFlags Flags which are passed through to protocol
       
  1247 @param aStatus On completion, KErrNone if successful, otherwise one of the system wide error codes. 
       
  1248 Note that KErrEof indicates either that a remote connection is 
       
  1249 closed, and that no more data is available for reading, or the socket has 
       
  1250 been shutdown with option RSocket::EStopInput.
       
  1251 @param aLen For non-datagram sockets, on return, a length which indicates how 
       
  1252 much data was read. This is the same as length of the returned aDesc. For 
       
  1253 datagram sockets, this parameter is not used.
       
  1254 
       
  1255 @capability Dependent on the type of socket so deferred to PRT */
       
  1256 	{
       
  1257 	aLen = someFlags;
       
  1258 
       
  1259 	//see comment in  RSocket::Send(const TDesC8 &aBuffer,TUint someFlags,TRequestStatus &aStatus)	
       
  1260 	SendReceive(ESoRecvFrom,TIpcArgs(&aLen,&anAddr,&aBuffer),aStatus);
       
  1261 	}
       
  1262 
       
  1263 EXPORT_C void RSocket::Connect(TSockAddr &anAddr,TRequestStatus &aStatus)
       
  1264 //
       
  1265 // Start a socket connecting ("active open")
       
  1266 //
       
  1267 /** Connects to a remote host asynchronously. 
       
  1268 
       
  1269 The address provided specifies the address of the remote host. 
       
  1270 
       
  1271 A socket may only have one connect operation outstanding at 
       
  1272 any one time. Once the connect is completed, the socket is ready to send 
       
  1273 or receive data. If a socket is unbound - i.e. Bind() has not been called 
       
  1274 yet - then it will automatically have a local address allocated. 
       
  1275 
       
  1276 Connect() is always required for protocols which do not have the KSIConnectionLess 
       
  1277 flag in their protocol information. If a protocol has the KSIConnectionLess 
       
  1278 flag, then Connect() may be used to set the address for all data sent from 
       
  1279 the socket, in which case Send()/Write() may be used in addition to SendTo().
       
  1280 
       
  1281 To use data in connection a protocol must have the flag KSIConnectData in 
       
  1282 its protocol information.
       
  1283 
       
  1284 To cancel a connect use CancelConnect().
       
  1285 
       
  1286 @param anAddr Address of remote host.
       
  1287 @param aStatus On completion, will contain an error code, see the system-wide 
       
  1288 error codes.
       
  1289 
       
  1290 @capability Dependent on the type of socket so deferred to PRT */
       
  1291 	{
       
  1292 	LOG( ESockLog::Printf(_L8("RSocket %08x:\tConnect(port=%d): tid %d"), this, anAddr.Port(), (TUint)RThread().Id() ) );
       
  1293 
       
  1294 	SendReceive(ESoConnect,TIpcArgs(&anAddr, NULL, NULL),aStatus);
       
  1295 	}
       
  1296 
       
  1297 EXPORT_C void RSocket::Connect(TSockAddr &anAddr,const TDesC8 &aConnectDataOut,TDes8 &aConnectDataIn,TRequestStatus &aStatus)
       
  1298 /** Connects to a remote host asynchronously. 
       
  1299 
       
  1300 The address provided specifies the address of the 
       
  1301 remote host. 
       
  1302 
       
  1303 Some protocols allow data to be sent in connect request packets 
       
  1304 which may be provided in the data-out descriptor. Some protocols may allow 
       
  1305 data to be sent in connect responses which may be collected in the data-in 
       
  1306 descriptor. 
       
  1307 
       
  1308 A socket may only have one connect operation outstanding at any 
       
  1309 one time. Once the connect is completed, the socket is ready to send or receive 
       
  1310 data. If a socket is unbound - i.e. Bind() has not been called yet - then 
       
  1311 it will automatically have a local address allocated. 
       
  1312 
       
  1313 Connect() is always required for protocols which do not have the KSIConnectionLess 
       
  1314 flag in their protocol information. If a protocol has the KSIConnectionLess 
       
  1315 flag, then Connect() may be used to set the address for all data sent from 
       
  1316 the socket, in which case Send()/Write() may be used in addition to SendTo().
       
  1317 
       
  1318 To use data in connection a protocol must have the flag KSIConnectData in 
       
  1319 its protocol information.
       
  1320 
       
  1321 To cancel a connect use CancelConnect().
       
  1322 
       
  1323 @param anAddr Address of remote host.
       
  1324 @param aDataOut A descriptor containing data to be sent.
       
  1325 @param aDataIn A descriptor to receive data.
       
  1326 @param aStatus On completion, will contain an error code. KErrBadHandle if the socket has already been
       
  1327  closed by the client; KErrAlreadyExists if the socket is already connected and it isn't a blocking 
       
  1328  connection; otherwise one of the system-wide error codes.
       
  1329 @panic EConnectingAlready if the socket is connection-oriented and a blocking connection is already in progress for the socket
       
  1330 
       
  1331 @capability Dependent on the type of socket so deferred to PRT */
       
  1332 	{
       
  1333 	SendReceive(ESoConnect,TIpcArgs(&anAddr,&aConnectDataOut,&aConnectDataIn),aStatus);
       
  1334 	}
       
  1335 		
       
  1336 EXPORT_C TInt RSocket::Bind(TSockAddr &anAddr)
       
  1337 /** Sets the local address of a socket. 
       
  1338 
       
  1339 When a socket is opened it has no name associated with it, and binding is 
       
  1340   required so data can be routed to the socket. 
       
  1341 
       
  1342 
       
  1343 Bind() should be called before Listen() or Connect(). The address supplied 
       
  1344 should be a derived class specific to the particular protocol the socket was 
       
  1345 opened on.
       
  1346 
       
  1347 @param anAddr Desired local address of socket.
       
  1348 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1349 codes. */
       
  1350 	{
       
  1351 	const TInt ret = SendReceive(ESoBind,TIpcArgs(&anAddr));
       
  1352 	LOG( ESockLog::Printf(_L8("RSocket %08x:\tBind(family=0x%04x, port=%d): client %d, ret=%d"),
       
  1353 			this, anAddr.Family(), anAddr.Port(), (TUint)RThread().Id(), ret));
       
  1354 	return ret;
       
  1355 	}
       
  1356 
       
  1357 EXPORT_C TInt RSocket::SetLocalPort(TInt aPort)
       
  1358 /** Sets the local port of a socket. Setting the local port is equivalent to calling 
       
  1359 Bind() with only the port set in the address.
       
  1360 
       
  1361 @param aPort Desired local port of socket.
       
  1362 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1363 codes. */
       
  1364 	{
       
  1365 	TSockAddr addr;
       
  1366 	addr.SetPort(aPort);
       
  1367 	return Bind(addr);
       
  1368 	}
       
  1369 
       
  1370 EXPORT_C void RSocket::Accept(RSocket& aBlankSocket,TRequestStatus& aStatus)
       
  1371 //
       
  1372 // Wait for incoming connections - accept a connection after a "passive open".
       
  1373 //
       
  1374 /** Facilitates a client/server connection from a remote socket. 
       
  1375 
       
  1376 Extracts the first pending connection on a queue of sockets, the queue size being 
       
  1377 previously specified by Listen(). On successful completion the blank socket is given 
       
  1378 the handle of the new socket and it may then be used to transfer data. After 
       
  1379 completion the accept socket may be used to make further connections with 
       
  1380 new blank sockets (see Open() on how to open a blank socket). 
       
  1381 
       
  1382 Accept() may be used for protocols which do not have the KSIConnectionLess 
       
  1383 flag in their protocol information.
       
  1384 
       
  1385 @param aBlankSocket A socket opened as a blank socket.
       
  1386 @param aStatus On completion, will contain an error code: see the system-wide 
       
  1387 error codes.
       
  1388 
       
  1389 @capability Dependent on the type of socket so deferred to PRT */
       
  1390 	{
       
  1391 	SendReceive(ESoAccept,TIpcArgs(NULL,aBlankSocket.SubSessionHandle(),NULL),aStatus);
       
  1392 	}
       
  1393 
       
  1394 EXPORT_C void RSocket::Accept(RSocket& aBlankSocket,TDes8 &aConnectData,TRequestStatus& aStatus)
       
  1395 //
       
  1396 // Wait for incoming connections - accept a connection after a "passive open".
       
  1397 //
       
  1398 /** Facilitates a client/server connection from a remote socket. 
       
  1399 
       
  1400 Extracts the first pending connection on a queue of sockets, the queue size being 
       
  1401 previously specified by Listen(). On successful completion the blank socket is given 
       
  1402 the handle of the new socket and it may then be used to transfer data. After 
       
  1403 completion the accept socket may be used to make further connections with 
       
  1404 new blank sockets (see Open() on how to open a blank socket). 
       
  1405 
       
  1406 This variant provides an additional descriptor argument to receive data
       
  1407 which may have been sent in a connect request. If there is a pending connection
       
  1408 in the listen queue when Accept() is called, the call will
       
  1409 complete immediately. Otherwise it will wait until a socket becomes available
       
  1410 in the queue and complete asynchronously.
       
  1411 
       
  1412 Accept() may be used for protocols which do not have the KSIConnectionLess 
       
  1413 flag in their protocol information.
       
  1414 
       
  1415 To receive data-in accepting, a protocol must have the flag KSIConnectData 
       
  1416 in its protocol information.
       
  1417 
       
  1418 @param aBlankSocket A socket opened as a blank socket.
       
  1419 @param aConnectData Data which may have been received in connection.
       
  1420 @param aStatus On completion, will contain an error code: see the system-wide 
       
  1421 error codes.
       
  1422 
       
  1423 @capability Dependent on the type of socket so deferred to PRT */
       
  1424 	{
       
  1425 	SendReceive(ESoAccept,TIpcArgs(NULL,aBlankSocket.SubSessionHandle(),&aConnectData),aStatus);
       
  1426 	}
       
  1427 
       
  1428 EXPORT_C TInt RSocket::Listen(TUint aQSize)
       
  1429 //
       
  1430 // Set up a socket for "passive open"
       
  1431 //
       
  1432 /** Sets up a socket to listen for incoming connections. 
       
  1433 
       
  1434 Before calling this procedure a socket should be opened on a specific protocol 
       
  1435 using Open() and the socket should be bound to a local address using Bind(). 
       
  1436 
       
  1437 Listen() creates a queue to hold incoming connections which can be married with 
       
  1438 blank sockets using Accept(). The call also allows data to be sent back to 
       
  1439 connecting peers if a protocol allows data to be passed in connect responses. 
       
  1440 Once a listen queue has been created it will continue to allow peers to connect 
       
  1441 until it is full, at which point it will reject any incoming connections as 
       
  1442 specified by protocol behaviour. When a socket is accepted by the client a space 
       
  1443 is made available in the queue.
       
  1444 
       
  1445 @param aQSize Size of listen queue.
       
  1446 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1447 codes. */
       
  1448 	{
       
  1449 	return SendReceive(ESoListen,TIpcArgs(aQSize,NULL));
       
  1450 	}
       
  1451 
       
  1452 EXPORT_C TInt RSocket::Listen(TUint aQSize,const TDesC8 &aConnectData)
       
  1453 //
       
  1454 // Set up socket for "passive open"
       
  1455 //
       
  1456 /** Sets up a socket to listen for incoming connections. 
       
  1457 
       
  1458 Before calling this procedure a socket should be opened on a specific protocol 
       
  1459 using Open() and the socket should be bound to a local address using Bind(). 
       
  1460 
       
  1461 Listen() creates a queue to hold incoming connections which can be married with 
       
  1462 blank sockets using Accept(). The call also allows data to be sent back to 
       
  1463 connecting peers if a protocol allows data to be passed in connect responses. 
       
  1464 Once a listen queue has been created it will continue to allow peers to connect 
       
  1465 until it is full, at which point it will reject any incoming connections as 
       
  1466 specified by protocol behaviour. When a socket is accepted by the client a space 
       
  1467 is made available in the queue.
       
  1468 
       
  1469 To use data-in listening, a protocol must have the flag KSIConnectData in 
       
  1470 its protocol information.
       
  1471 
       
  1472 @param aQSize Size of listen queue.
       
  1473 @param aDataOut A descriptor containing data to be sent in connect responses.
       
  1474 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1475 codes. */
       
  1476 	{
       
  1477 	return SendReceive(ESoListen,TIpcArgs(aQSize,&aConnectData,aConnectData.Length()));
       
  1478 	}
       
  1479 
       
  1480 EXPORT_C TInt RSocket::SetOpt(TUint anOptionName,TUint anOptionLevel,const TDesC8& anOption /*=TPtrC(NULL,0)*/)
       
  1481 /** Sets a socket option. The socket server has options which are generic to all 
       
  1482 sockets and protocols may add specific options.
       
  1483 
       
  1484 Options available for all protocols can be set with anOptionLevel set to KSOLSocket. 
       
  1485 See individual protocol notes for other socket options. 
       
  1486 
       
  1487 @param anOptionName An integer constant which identifies an option.
       
  1488 @param anOptionLevel An integer constant which identifies level of an option: 
       
  1489 i.e. an option level groups related options together.
       
  1490 @param anOption Option value packaged in a descriptor.
       
  1491 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1492 codes. 
       
  1493 
       
  1494 @capability Dependent on the type of operation so deferred to PRT.  See documentation
       
  1495 of constant values used in aOptionName and aOptionLevel for more information */
       
  1496 	{
       
  1497 	//return SendReceive(ESoSetOpt,TIpcArgs(anOptionName,&anOption,anOption.Length(),anOptionLevel));
       
  1498 	return SendReceive(ESoSetOpt,TIpcArgs(anOptionName,&anOption,anOptionLevel));
       
  1499 
       
  1500 	}
       
  1501 
       
  1502 EXPORT_C TInt RSocket::SetOpt(TUint anOptionName,TUint anOptionLevel,TInt anOption)
       
  1503 /** Sets a socket option. The socket server has options which are generic to all 
       
  1504 sockets and protocols may add specific options.
       
  1505 
       
  1506 Options available for all protocols can be set with anOptionLevel set to KSOLSocket. 
       
  1507 See individual protocol notes for other socket options. 
       
  1508 
       
  1509 @param anOptionName An integer constant which identifies an option.
       
  1510 @param anOptionLevel An integer constant which identifies level of an option: 
       
  1511 i.e. an option level groups related options together.
       
  1512 @param anOption Option value as an integer.
       
  1513 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1514 codes. 
       
  1515 
       
  1516 @capability Dependent on the type of operation so deferred to PRT.  See documentation
       
  1517 of constant values used in aOptionName and aOptionLevel for more information */
       
  1518 	{
       
  1519 
       
  1520 	TPtr8 optionDes((TUint8*)&anOption,sizeof(TInt),sizeof(TInt));
       
  1521 	return SetOpt(anOptionName,anOptionLevel,optionDes);
       
  1522 	}
       
  1523 
       
  1524 EXPORT_C TInt RSocket::GetOpt(TUint anOptionName,TUint anOptionLevel,TDes8& anOption)
       
  1525 /** Gets a socket option. The socket server has options which are generic to all 
       
  1526 sockets and protocols may add specific options.
       
  1527 
       
  1528 Options available for all protocols can be got with anOptionLevel set to KSOLSocket. 
       
  1529 See individual protocol notes for other socket options. 
       
  1530 
       
  1531 @param anOptionName An integer constant which identifies an option.
       
  1532 @param anOptionLevel An integer constant which identifies level of an option.
       
  1533 @param anOption On return, option value packaged in a descriptor.
       
  1534 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1535 codes.
       
  1536 
       
  1537 @capability Dependent on the type of operation so deferred to PRT.  See documentation
       
  1538 of constant values used in aOptionName and aOptionLevel for more information */
       
  1539 	{
       
  1540 	//return SendReceive(ESoGetOpt,TIpcArgs(anOptionName,&anOption,anOption.MaxLength(),anOptionLevel));
       
  1541 	return SendReceive(ESoGetOpt,TIpcArgs(anOptionName,&anOption,anOptionLevel));
       
  1542 	}
       
  1543 
       
  1544 EXPORT_C TInt RSocket::GetOpt(TUint anOptionName,TUint anOptionLevel,TInt& anOption)
       
  1545 /** Gets a socket option. The socket server has options which are generic to all 
       
  1546 sockets and protocols may add specific options.
       
  1547 
       
  1548 Options available for all protocols can be got with anOptionLevel set to KSOLSocket. 
       
  1549 See individual protocol notes for other socket options. 
       
  1550 
       
  1551 @param anOptionName An integer constant which identifies an option.
       
  1552 @param anOptionLevel An integer constant which identifies level of an option.
       
  1553 @param anOption On return, option value as an integer.
       
  1554 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1555 codes.
       
  1556 
       
  1557 @capability Dependent on the type of operation so deferred to PRT.  See documentation
       
  1558 of constant values used in aOptionName and aOptionLevel for more information */
       
  1559 	{
       
  1560 	TPtr8 optionDes((TUint8*)&anOption,sizeof(TInt),sizeof(TInt));
       
  1561 	return GetOpt(anOptionName,anOptionLevel,optionDes);
       
  1562 	}
       
  1563 
       
  1564 EXPORT_C void RSocket::Ioctl(TUint aCommand,TRequestStatus& aStatus,TDes8* aDesc /*=NULL*/,TUint aLevel /*=KLevelUnspecified*/)
       
  1565 /** Applies an asynchronous I/O control operation on a socket. Data may be passed and 
       
  1566 received if a descriptor address is provided as an argument. Only one Ioctl() 
       
  1567 operation may be outstanding for each socket.
       
  1568 
       
  1569 Commands available for all protocols can be set withaLevel set to KSOLSocket. 
       
  1570 See individual protocol notes for other commands. 
       
  1571 
       
  1572 @param aCommand Ioctl command.
       
  1573 @param aStatus On completion, will contain an error code: see the system-wide 
       
  1574 error codes.
       
  1575 @param aDesc Pointer to a descriptor in which data may be sent and received 
       
  1576 on completion
       
  1577 @param aLevel Control operation level
       
  1578 
       
  1579 @capability Dependent on the type of operation so deferred to PRT.  See documentation
       
  1580 of constant values used in aOptionName and aOptionLevel for more information */
       
  1581 	{
       
  1582 	SendReceive(ESoIoctl,TIpcArgs(aCommand,aDesc,aLevel),aStatus);
       
  1583 	}
       
  1584 
       
  1585 EXPORT_C TInt RSocket::GetDisconnectData(TDes8 &aDesc)
       
  1586 /** Gets data for use in the disconnection of a socket, namely the remote name of 
       
  1587 the connected socket.
       
  1588 
       
  1589 This data has been received in a protocol disconnect message.
       
  1590 
       
  1591 To use the data in disconnection, a protocol must have the flagKSIConnectData in 
       
  1592 its protocol information.
       
  1593 
       
  1594 @param aDesc A descriptor to receive data.
       
  1595 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1596 codes. */
       
  1597 	{
       
  1598 	return SendReceive(ESoGetDiscData,TIpcArgs(&aDesc));
       
  1599 	}
       
  1600 
       
  1601 EXPORT_C void RSocket::LocalName(TSockAddr &anAddr)
       
  1602 /** Gets the local address of a bound socket. 
       
  1603 
       
  1604 The local address is set either by calling Bind(), or is automatically set 
       
  1605 when Connect() is called. 
       
  1606 
       
  1607 If a socket is created through Accept() then a socket will inherit the port 
       
  1608 of its parent unless otherwise specified by a protocol's behaviour. 
       
  1609 
       
  1610 Depending on a protocol implementation, additional information may be gained 
       
  1611 through this call.
       
  1612 
       
  1613 @param anAddr Local address which is filled in on return. */
       
  1614 	{
       
  1615 	SendReceive(ESoGetLocalName,TIpcArgs(&anAddr));
       
  1616 	}
       
  1617 
       
  1618 EXPORT_C TUint RSocket::LocalPort()
       
  1619 /** Gets the local port number of a bound socket. 
       
  1620 
       
  1621 Getting the local port is similar to getting the local name.
       
  1622 
       
  1623 @see LocalName() for a description.
       
  1624 @return The local port of a socket. */
       
  1625 	{
       
  1626 	TSockAddr addr;
       
  1627 	LocalName(addr);
       
  1628 	return addr.Port();
       
  1629 	}
       
  1630 	
       
  1631 EXPORT_C void RSocket::RemoteName(TSockAddr &anAddr)
       
  1632 /** Gets the remote name of a connected socket. 
       
  1633 
       
  1634 The remote name of a socket is associated with the remote host a socket is 
       
  1635 connected to. The remote name is only valid for a connected socket. A socket 
       
  1636 is either connected through calling Connect() or Accept().
       
  1637 
       
  1638 @param anAddr Remote address which is filled in on return. */
       
  1639 	{
       
  1640 	SendReceive(ESoGetRemoteName,TIpcArgs(&anAddr));
       
  1641 	}
       
  1642 
       
  1643 EXPORT_C void RSocket::CancelSend()
       
  1644 /** Cancels an outstanding Send() operation. 
       
  1645 
       
  1646 Calling the function will cause any outstanding send operation to complete 
       
  1647 prematurely. The state of a socket after a send is cancelled is defined by 
       
  1648 the characteristics of the protocol. */
       
  1649 	{
       
  1650 	SendReceive(ESoCancelSend,TIpcArgs());
       
  1651 	}
       
  1652 
       
  1653 EXPORT_C void RSocket::CancelRecv()
       
  1654 /** Cancels an outstanding Recv() operation. 
       
  1655 
       
  1656 Calling this function will cause any outstanding receive operation to complete 
       
  1657 prematurely. The state of a socket after a receive is cancelled is defined 
       
  1658 by the characteristics of the protocol. */
       
  1659 	{
       
  1660 	SendReceive(ESoCancelRecv,TIpcArgs());
       
  1661 	}
       
  1662 
       
  1663 EXPORT_C void RSocket::CancelRead()
       
  1664 /** Cancels an outstanding Read() operation. 
       
  1665 
       
  1666 Calling this function will cause any outstanding Read() operation to complete 
       
  1667 prematurely. The state of a socket after a receive is cancelled is defined 
       
  1668 by the characteristics of the protocol. */
       
  1669 	{
       
  1670 	SendReceive(ESoCancelRecv,TIpcArgs());
       
  1671 	}
       
  1672 
       
  1673 EXPORT_C void RSocket::CancelWrite()
       
  1674 /** Cancels an outstanding Write() operation. 
       
  1675 
       
  1676 Calling the function will cause any outstanding Write() operation to complete 
       
  1677 prematurely. The state of a socket after a send is cancelled is defined by 
       
  1678 the characteristics of the protocol. */
       
  1679 	{
       
  1680 	SendReceive(ESoCancelSend,TIpcArgs());
       
  1681 	}
       
  1682 
       
  1683 EXPORT_C void RSocket::CancelConnect()
       
  1684 /** Cancels an outstanding connect operation. 
       
  1685 
       
  1686 Will cause any outstanding connect operation to complete prematurely.
       
  1687 
       
  1688 The state of a socket after a connect is cancelled is defined by the characteristics 
       
  1689 of the protocol. */
       
  1690 	{
       
  1691 	SendReceive(ESoCancelConnect,TIpcArgs());
       
  1692 	}
       
  1693 
       
  1694 EXPORT_C void RSocket::CancelIoctl()
       
  1695 /** Cancels an outstanding Ioctl() operation. 
       
  1696 
       
  1697 Will cause any outstanding Ioctl operation to complete prematurely. 
       
  1698 
       
  1699 The state of a socket after a connect is cancelled is defined by the characteristics 
       
  1700 of the protocol. */
       
  1701 	{
       
  1702 	SendReceive(ESoCancelIoctl,TIpcArgs());
       
  1703 	}
       
  1704 
       
  1705 
       
  1706 EXPORT_C void RSocket::CancelAccept()
       
  1707 /** Cancels an outstanding accept operation. 
       
  1708 
       
  1709 Will cause any outstanding accept operation to complete prematurely. */
       
  1710 	{
       
  1711 	SendReceive(ESoCancelAccept,TIpcArgs());
       
  1712 	}
       
  1713 
       
  1714 
       
  1715 EXPORT_C void RSocket::CancelAll()
       
  1716 /** Cancels all outstanding operations. 
       
  1717 
       
  1718 Will cause all outstanding operations to complete prematurely. 
       
  1719 
       
  1720 Outstanding operations for a socket include: read, write, Ioctl, connect, 
       
  1721 accept and shutdown. All of these operations will be completed by this call. */
       
  1722 	{
       
  1723 	SendReceive(ESoCancelAll,TIpcArgs());
       
  1724 	}
       
  1725 
       
  1726 EXPORT_C TInt RSocket::Info(TProtocolDesc &aProtocol)
       
  1727 /** Gets information in the protocol description for the protocol which a socket 
       
  1728 is opened on.
       
  1729 
       
  1730 @param aProtocol A protocol description type to hold protocol information.
       
  1731 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1732 codes. */
       
  1733 	{
       
  1734 	TPckg<TProtocolDesc> protDesc(aProtocol);
       
  1735 
       
  1736 	return SendReceive(ESoSocketInfo,TIpcArgs(&protDesc));
       
  1737 	}
       
  1738 
       
  1739 EXPORT_C TInt RSocket::Name(TName& aName)
       
  1740 /** Gets a unique system name for the socket. The purpose of this is to identify 
       
  1741 the socket in a call to Transfer().
       
  1742 
       
  1743 @param aName System name for the socket
       
  1744 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1745 codes. */
       
  1746     {
       
  1747 	return SendReceive(ESoReference,TIpcArgs(&aName));
       
  1748     }
       
  1749 
       
  1750 EXPORT_C TInt RSocket::Transfer(RSocketServ& aServer, const TDesC& aName)
       
  1751 //
       
  1752 // Transfer socket identified by name to this session
       
  1753 //
       
  1754 /** Transfers a socket from one socket server session to another. It creates the 
       
  1755 socket in the target session, and removes the socket from the source session. 
       
  1756 The call is made on an uninitialised RSocket object. The socket system name 
       
  1757 is used to identify the socket to transfer. 
       
  1758 
       
  1759 If the call fails, the socket that is being transferred remains with the original 
       
  1760 session. Success or failure can be checked on the originating socket by calling 
       
  1761 Info(), which returns KErrNone if the transfer failed, and KErrBadHandle if 
       
  1762 it succeeded.
       
  1763 
       
  1764 Platsec considerations require that the source socket must set itself transferable
       
  1765 before any attempt to transfer the socket to the destination socket. This is done using 
       
  1766 a setopt in the following way
       
  1767 
       
  1768 @code
       
  1769 		_LIT_SECURITY_POLICY_Cn(KProcPolicy, cap1,cap2,...capn);
       
  1770 		ret = destsock.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package());
       
  1771 @endcode
       
  1772 
       
  1773 where cap1,cap2...capn are the capabilities that the destination process MUST have in 
       
  1774 order to affect the transfer.
       
  1775 
       
  1776 An example is:
       
  1777 
       
  1778 @code
       
  1779 		_LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl);
       
  1780 		ret = destsock.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package());
       
  1781 @endcode
       
  1782 
       
  1783 If the setOpt is not set or the destination process does not have sufficient capabilities then
       
  1784 the function will return KErrPermissionDenied    
       
  1785 
       
  1786 @param aServer The session into which to transfer the socket.
       
  1787 @param aName The system name, as obtained from a call to Name(), of the socket 
       
  1788 that you want to transfer.
       
  1789 @return KErrNone if successful, otherwise another of the system-wide error 
       
  1790 codes. 
       
  1791 
       
  1792 @capability Dependent on the capabilities defined in the setOpt by the source Socket */
       
  1793 	{
       
  1794 	return CreateSubSession(aServer, ESoTransfer, TIpcArgs(&aName));
       
  1795 	}