genericopenlibs/openenvcore/backend/inc/fdesc.h
branchRCL_3
changeset 54 4332f0f7be53
parent 53 9d9daa0f4b62
child 56 acd3cd4aaceb
equal deleted inserted replaced
53:9d9daa0f4b62 54:4332f0f7be53
    20 
    20 
    21 #ifndef _FDESC_H
    21 #ifndef _FDESC_H
    22 #define _FDESC_H
    22 #define _FDESC_H
    23 
    23 
    24 #include <e32std.h>
    24 #include <e32std.h>
       
    25 #include <e32atomics.h>
    25 #include <e32cons.h>
    26 #include <e32cons.h>
    26 #include <f32file.h>
    27 #include <f32file.h>
    27 #include <es_sock.h>
    28 #include <es_sock.h>
    28 #include <c32comm.h>
    29 #include <c32comm.h>
    29 #include <stddef.h>
    30 #include <stddef.h>
    62 #define RFILE 	RFile
    63 #define RFILE 	RFile
    63 #define FSIZE	TInt
    64 #define FSIZE	TInt
    64 
    65 
    65 #endif //SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS
    66 #endif //SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS
    66 
    67 
       
    68 // Atomic socket operations support
       
    69 
       
    70 #define ATOMICSOCKETOP(realcall,on_error) \
       
    71     { \
       
    72     if (__e32_atomic_tau_ord32((void *)&iCount, 0x8000, 0, 1) >= 0x8000) \
       
    73         { \
       
    74         on_error; \
       
    75         } \
       
    76     else \
       
    77         { \
       
    78         realcall; \
       
    79         __e32_atomic_tas_ord32((void *)&iCount, 0, -1, 0); \
       
    80         } \
       
    81     }
       
    82 
       
    83 #define NOP 
    67 
    84 
    68 //Enumarations for Polling
    85 //Enumarations for Polling
    69 enum TPollMode
    86 enum TPollMode
    70     {
    87     {
    71     EReadyForReading = 1,
    88     EReadyForReading = 1,
   509 	 const TUint& GetSelectEvents()
   526 	 const TUint& GetSelectEvents()
   510 		 {
   527 		 {
   511 		 iIoctlLock.Signal();
   528 		 iIoctlLock.Signal();
   512 		 return iSelectEvents();
   529 		 return iSelectEvents();
   513 		 }
   530 		 }
   514 	 inline int CreateLock() 
   531 	 
       
   532 	 inline TInt CreateLock() 
   515 		 {
   533 		 {
   516 		 return (iIoctlLock.CreateLocal(1)|| iReadLock.CreateLocal() || iWriteLock.CreateLocal());
   534 	     TInt err = iIoctlLock.CreateLocal(1) || iReadLock.CreateLocal() || iWriteLock.CreateLocal();
       
   535 	     if (err != KErrNone)
       
   536 	         {
       
   537              // closes on unopened handles are safe
       
   538              iIoctlLock.Close();
       
   539              iReadLock.Close();
       
   540              iWriteLock.Close();
       
   541 	         }
       
   542 	     return err;
   517 		 }
   543 		 }
       
   544 		 
   518 	 inline RSemaphore& GetIoctlLock()
   545 	 inline RSemaphore& GetIoctlLock()
   519 		 {
   546 		 {
   520 		 return iIoctlLock;
   547 		 return iIoctlLock;
   521 		 }
   548 		 }
   522 	 inline TBool GetConnectionProgress()
   549 	 inline TBool GetConnectionProgress()
   529 		 iConnectInProgress = aInProgress;
   556 		 iConnectInProgress = aInProgress;
   530 		 }
   557 		 }
   531 	 
   558 	 
   532 protected:
   559 protected:
   533 		//rearrange these 
   560 		//rearrange these 
   534 	CSockDescBase():iAddrFamily(-1),iProtocol(KUndefinedProtocol),iIoctlFlag(EFalse)
   561 	CSockDescBase():iAddrFamily(-1),iProtocol(KUndefinedProtocol),iIoctlFlag(EFalse),iCount(0)
   535 	{
   562 	{
   536 
   563 	
   537 	}	
   564 	}	
   538 	RSocket iSocket;
   565 	RSocket iSocket;
   539 	TSockXfrLength iLength;
   566 	TSockXfrLength iLength;
   540 	TFileName iPath;
   567 	TFileName iPath;
   541 	TPckgBuf<TUint> iSelectEvents;
   568 	TPckgBuf<TUint> iSelectEvents;
   543 	TInt iProtocol;
   570 	TInt iProtocol;
   544 	TInt iStyle;
   571 	TInt iStyle;
   545 	// For preventing simultaneous ioctl calls.
   572 	// For preventing simultaneous ioctl calls.
   546 	// No native support.
   573 	// No native support.
   547 	RSemaphore iIoctlLock;
   574 	RSemaphore iIoctlLock;
       
   575 	// Is this required?
   548 	TBool iIoctlFlag;
   576 	TBool iIoctlFlag;
   549 	
   577 	// Safeguard against issue of a second Read/Write request while the first is pending.
       
   578 	// The iReadLock also guards OpenUsingPreference
   550 	//For locking the descriptor before any operation.
   579 	//For locking the descriptor before any operation.
   551 	//To make it thread safe.
   580 	//To make it thread safe.
   552 	RFastLock iReadLock;
   581 	RFastLock iReadLock;
   553 	RFastLock iWriteLock;
   582 	RFastLock iWriteLock;
   554 
   583 
   555 	//Flag to mark the connect status of a non-blocking socket as "in progress"
   584 	//Flag to mark the connect status of a non-blocking socket as "in progress"
   556 	//to prevent duplicate connection request
   585 	//to prevent duplicate connection request
   557 	TBool iConnectInProgress;
   586 	TBool iConnectInProgress;
       
   587 	volatile TInt iCount;
   558 protected:
   588 protected:
   559 
   589 
   560 	inline TInt isStream() const	// inline, but private
   590 	inline TInt isStream() const	// inline, but private
   561 		{ 
   591 		{ 
   562 		return iStyle==SOCK_STREAM; 
   592 		return iStyle==SOCK_STREAM; 
   657 	void FindConnectionDetailsL(CArrayFixFlat<TAccessPointRecord>*& aRecordPtr, TInt& aCount);    
   687 	void FindConnectionDetailsL(CArrayFixFlat<TAccessPointRecord>*& aRecordPtr, TInt& aCount);    
   658 	void FindConnectionInfoL(TAccessPointRecord &aRecord,char *ptr);
   688 	void FindConnectionInfoL(TAccessPointRecord &aRecord,char *ptr);
   659 	TInt GetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
   689 	TInt GetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
   660 	TInt SetInterafceParamInfo( void *aParam,TInt aType);
   690 	TInt SetInterafceParamInfo( void *aParam,TInt aType);
   661 	TInt SetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
   691 	TInt SetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
       
   692 	
       
   693 	TInt maybe_reopen_socket()
       
   694 	    {
       
   695 	    TInt err = KErrNone;
       
   696 	    if (!__e32_atomic_load_acq32(&iSocketPtr))
       
   697 	        {
       
   698             iReadLock.Wait();
       
   699             if (!iSocketPtr)
       
   700                 {
       
   701                 err = OpenUsingPreference();
       
   702                 }
       
   703             iReadLock.Signal();
       
   704 	        }
       
   705 	    return err;
       
   706 	    }
       
   707 	
   662 	enum InterfaceType
   708 	enum InterfaceType
   663 		{
   709 		{
   664 		EACCESS_POINT,
   710 		EACCESS_POINT,
   665 		EACTIVE_CONNECTION,
   711 		EACTIVE_CONNECTION,
   666 		EACTIVE_GETIP,
   712 		EACTIVE_GETIP,