1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/backend/inc/fdesc.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1049 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Abstraction representing a UNIX file descriptor
1.18 +// CFileDescBase maintains the simple semantics of
1.19 +// Dup() and Close(), so the final Close() will
1.20 +// delete the object and hence call the destructor.
1.21 +//
1.22 +//
1.23 +
1.24 +#ifndef _FDESC_H
1.25 +#define _FDESC_H
1.26 +
1.27 +#include <e32std.h>
1.28 +#include <e32atomics.h>
1.29 +#include <e32cons.h>
1.30 +#include <f32file.h>
1.31 +#include <es_sock.h>
1.32 +#include <c32comm.h>
1.33 +#include <stddef.h>
1.34 +#include <cdblen.h>
1.35 +#include <commdb.h>
1.36 +#include <commdbconnpref.h>
1.37 +#include <sys/stat.h>
1.38 +#include <fcntl.h>
1.39 +#include <rpipe.h>
1.40 +#include <in_sock.h>
1.41 +
1.42 +#include "base.h"
1.43 +#include "StdioClient.h"
1.44 +
1.45 +//FD attributes used internally by the backend
1.46 +const TUint KInvalidFd = 0x00000001;
1.47 +const TUint KMMapedFd = 0x00000002;
1.48 +const TUint KCloseonExec = 0x00000004;
1.49 +const TUint KPipeFd = 0x00000008;
1.50 +const TUint KIoctlOutstanding = 0x00000010;
1.51 +const TUint KConsoleFd = 0x00000020;
1.52 +const TUint KFifoFd = 0x00000030;
1.53 +const TUint KSpawnCloseInChild = 0x00000040;
1.54 +
1.55 +#define SET_CLOSE_ON_EXEC_FLG (1 << 2)
1.56 +
1.57 +#if defined(SYMBIAN_OE_LARGE_FILE_SUPPORT) && !defined(SYMBIAN_OE_NO_LFS)
1.58 +
1.59 +//Large File Support - Use RFile64 and 64 bit file sizes
1.60 +#define RFILE RFile64
1.61 +#define FSIZE TInt64
1.62 +
1.63 +#else
1.64 +
1.65 +//No large file support - Use RFile and 32 bit file sizes
1.66 +#define RFILE RFile
1.67 +#define FSIZE TInt
1.68 +
1.69 +#endif //SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS
1.70 +
1.71 +// Atomic socket operations support
1.72 +
1.73 +#define ATOMICSOCKETOP(realcall,on_error) \
1.74 + { \
1.75 + if (__e32_atomic_tau_ord32((void *)&iCount, 0x8000, 0, 1) >= 0x8000) \
1.76 + { \
1.77 + on_error; \
1.78 + } \
1.79 + else \
1.80 + { \
1.81 + realcall; \
1.82 + __e32_atomic_tas_ord32((void *)&iCount, 0, -1, 0); \
1.83 + } \
1.84 + }
1.85 +
1.86 +#define NOP
1.87 +
1.88 +//Enumarations for Polling
1.89 +enum TPollMode
1.90 + {
1.91 + EReadyForReading = 1,
1.92 + EReadyForWriting = 2,
1.93 + EAnyException = 4
1.94 + };
1.95 +
1.96 +//Enumarations for Redirection Server
1.97 +enum TRedirConnState
1.98 + {
1.99 + ENotConnected,
1.100 + EConnected,
1.101 + ENoServer
1.102 + };
1.103 +
1.104 +//Enumerations for the console echo
1.105 +enum TConsoleEcho
1.106 + {
1.107 + EOff = 0, //Turn Off the echo
1.108 + EOn = 1, //Turn On the echo
1.109 + EPrintValid = 33, //Printable ascii character set <33-126>
1.110 + EPrintInvalid=127
1.111 + };
1.112 +
1.113 +// The base class for all flavours of FileDescriptor
1.114 +//
1.115 +class CSocketDesc;
1.116 +
1.117 +NONSHARABLE_CLASS(CFileDescBase) : public CBase
1.118 +/*
1.119 +@internalComponent
1.120 +*/
1.121 + {
1.122 +public:
1.123 +
1.124 + static CFileDescBase* Open(const wchar_t* name, int mode, int perms, TInt& err);
1.125 + static CFileDescBase* Socket(RSocketServ& aSs, int family, int style, int protocol, TInt& err);
1.126 +
1.127 + virtual void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.128 + virtual TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
1.129 + virtual void ReadCancel();
1.130 +
1.131 + virtual void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.132 + virtual TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
1.133 + virtual void WriteCancel();
1.134 + virtual TInt SetAtt(TUint aSetAttMask, TUint aClearAttMask);
1.135 +
1.136 + virtual void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.137 + virtual TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.138 + virtual void IoctlCancel();
1.139 +
1.140 + virtual void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus);
1.141 + virtual void RecvFromCancel();
1.142 +
1.143 + virtual void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen,int flags, TRequestStatus& aStatus);
1.144 +
1.145 + virtual void SendToCancel();
1.146 +
1.147 + virtual TInt CompletionStatus(TInt& aLength, TInt aStatus);
1.148 +
1.149 + virtual void Sync(TRequestStatus& aStatus);
1.150 + virtual void SyncCancel();
1.151 +
1.152 + virtual void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs,TSockAddr *aAddr);
1.153 + virtual void AcceptCancel();
1.154 +
1.155 + virtual void Connect(const struct sockaddr* aAddr,unsigned long size,TRequestStatus& aStatus);
1.156 + virtual void ConnectCancel();
1.157 + virtual TBool GetConnectionProgress();
1.158 + virtual void SetConnectionProgress( TBool aInProgress );
1.159 +
1.160 + virtual void Shutdown(TUint aHow,TRequestStatus& aStatus);
1.161 + virtual void ShutdownCancel();
1.162 +
1.163 + virtual TBool TimedRead() {return EFalse;} //default implementation
1.164 + TInt TimeoutValue() const {return iReadTimeout;}
1.165 +
1.166 + virtual TInt LSeek(off_t& offset, int whence);
1.167 + virtual TInt FStat(struct stat* st);
1.168 + virtual TInt Bind(const struct sockaddr* addr, unsigned long size);
1.169 + virtual TInt Listen(TUint qSize);
1.170 + virtual TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize);
1.171 + virtual TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption);
1.172 + virtual TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption);
1.173 + virtual TInt Fcntl(TUint anArg, TUint aCmd);
1.174 +
1.175 + virtual TInt Poll(TPollMode aMode,TBool& aReadyStatus,TInt& aErrno);
1.176 + virtual TInt Poll(TUint aEvents);
1.177 + virtual TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout);
1.178 + virtual void TweakWatchedEvents(TUint& events);
1.179 + virtual TInt TweakReadyEvents(TInt errval);
1.180 + virtual void CancelNotify();
1.181 +
1.182 + //Truncate the File
1.183 + virtual TInt Truncate(off_t /*anOffset*/)
1.184 + {
1.185 + return KErrNotSupported;
1.186 + }
1.187 + //Type of the Descriptor
1.188 + virtual TInt Type()
1.189 + {
1.190 + return EBaseDesc;
1.191 + }
1.192 +
1.193 + //Set/reset the Attributes of the FD
1.194 + inline void SetAttributes( TUint32 aBit, TBool aFlag )
1.195 + {
1.196 + if( aFlag )
1.197 + {
1.198 + //Set the bit to 1
1.199 + iFdAttrib |= aBit;
1.200 + }
1.201 + else
1.202 + {
1.203 + //Reset the bit to 0
1.204 + iFdAttrib &= ~aBit;
1.205 + }
1.206 + }
1.207 +
1.208 + //Get the Attributes of the FD
1.209 + inline const TUint32 Attributes() const
1.210 + {
1.211 + return iFdAttrib;
1.212 + }
1.213 +
1.214 + inline const TUint32 FcntlFlag() const
1.215 + {
1.216 + return iFcntlFlag;
1.217 + }
1.218 +
1.219 + static inline void Cleanup(TAny *aPtr)
1.220 + {
1.221 + ((CFileDescBase*)aPtr)->Close();
1.222 + }
1.223 +
1.224 + inline void PushLC()
1.225 + {
1.226 + CleanupStack::PushL(TCleanupItem(Cleanup,this));
1.227 + }
1.228 +
1.229 + IMPORT_C TInt Close();
1.230 + virtual void UserClose() {return;}
1.231 + inline CFileDescBase* Dup();
1.232 + inline void SetFid(TInt aFid) { iFid = aFid; }
1.233 + virtual void SetFids(void *aFids);
1.234 +
1.235 + inline void operator delete(TAny *aPtr) __NO_THROW
1.236 + {
1.237 + Backend()->Free(aPtr);
1.238 + }
1.239 +
1.240 + inline void operator delete(TAny *aPtr, TLeave) __NO_THROW
1.241 + {
1.242 + Backend()->Free(aPtr);
1.243 + }
1.244 +
1.245 + inline void operator delete(TAny *aPtr, TAny*) __NO_THROW
1.246 + {
1.247 + Backend()->Free(aPtr);
1.248 + }
1.249 +
1.250 + TBool ReadIsTimed;
1.251 + TBool ReadWasCancelled;
1.252 +
1.253 +protected:
1.254 + CFileDescBase( TUint aFcntl = 0, TUint32 aFdAttrib = 0 );
1.255 + virtual TInt FinalClose();
1.256 + static void Complete(TRequestStatus& aStatus, TInt aResult);
1.257 + TInt iReadTimeout;
1.258 + //Used in case of CRedirDesc
1.259 + TInt iFid;
1.260 + //For FD's fcntl
1.261 + TUint iFcntlFlag;
1.262 + //For FD's other attributes
1.263 + TUint32 iFdAttrib;
1.264 +
1.265 +private:
1.266 + //Check if the path corresponds to a directory
1.267 + static TBool CheckIfDirectory(const TDesC& aPath, RFs& aFs);
1.268 +
1.269 +public:
1.270 + enum TDescType
1.271 + {
1.272 + EBaseDesc,
1.273 + EFileDesc,
1.274 + EFileTempDesc,
1.275 + ESocketDesc,
1.276 + ESerialDesc,
1.277 + EDirDesc,
1.278 + ETtyDesc,
1.279 + EPopenPipeDesc,
1.280 + EPipeDesc,
1.281 + ERedirDesc,
1.282 + EStdErrDesc,
1.283 + EFileSocketDesc
1.284 + };
1.285 +private:
1.286 + TInt iDupCount;
1.287 +public:
1.288 + // Poll is required to return any of the requested events.
1.289 + // In case of any error, "iPollErr" should be checked by the socket-descriptor
1.290 + // to take any corrective action.
1.291 + TInt iPollErr;
1.292 + };
1.293 +
1.294 +
1.295 +inline CFileDescBase* CFileDescBase::Dup ()
1.296 + { iDupCount += 1; return this; }
1.297 +
1.298 +
1.299 +NONSHARABLE_CLASS(CTtyDesc) : public CFileDescBase
1.300 +/*
1.301 +Abstraction of a teletype device, which will be used for
1.302 +the console.
1.303 +@internalComponent
1.304 +*/
1.305 + {
1.306 +public:
1.307 + inline CTtyDesc(CConsoleBase *c);
1.308 + inline CTtyDesc();
1.309 + ~CTtyDesc();
1.310 + virtual TInt Type()
1.311 + {
1.312 + return ETtyDesc;
1.313 + }
1.314 + void Read(TDes8& aDesc, TRequestStatus &aStatus);
1.315 + void ReadCancel();
1.316 + TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
1.317 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.318 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.319 + TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.320 + TInt SetEcho(TUint8 aEcho);
1.321 +protected:
1.322 + virtual TInt FinalClose();
1.323 +private:
1.324 + void MapCodeAndEcho(TDes8& aDesc, TKeyCode aCode);
1.325 + void CheckConsoleCreated();
1.326 + void Write(TDes8& aDesc);
1.327 + CConsoleBase *iConsole;
1.328 + //To store last non-modifiable data position and flag for reading data
1.329 + TInt iCurPosX;
1.330 + TInt iCurPosY;
1.331 + TBool iReadingData;
1.332 + TUint8 iEchoVal;
1.333 + };
1.334 +
1.335 +inline CTtyDesc::CTtyDesc(CConsoleBase *c) : CFileDescBase(), iConsole(c), iEchoVal(EOn){}
1.336 +inline CTtyDesc::CTtyDesc() : CFileDescBase(), iEchoVal(EOn) {}
1.337 +
1.338 +
1.339 +NONSHARABLE_CLASS(CRedirDesc) : public CFileDescBase
1.340 +/*
1.341 +client-side CRedirDesc desc class which will be used to connecting to the Redirection Server
1.342 +@internalComponent
1.343 +*/
1.344 + {
1.345 +public:
1.346 + CRedirDesc();
1.347 + virtual TInt Type()
1.348 + {
1.349 + return ERedirDesc;
1.350 + }
1.351 + virtual void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.352 + virtual void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.353 + TInt WriteCompletion(TDes8& aDesc, TInt /*aStatus*/);
1.354 + TInt ReadCompletion(TDes8& aDesc, TInt /*aStatus*/);
1.355 + virtual TInt Fcntl(TUint anArg, TUint aCmd);
1.356 + TInt FinalClose();
1.357 + TInt Configure();
1.358 + TInt Poll(TUint aEvents);
1.359 + TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout);
1.360 + TInt TweakReadyEvents(TInt errval);
1.361 + void CancelNotify();
1.362 + TInt SetEcho(TUint8 aEcho);
1.363 + TBool iReadNone;
1.364 + TBool iWriteNone;
1.365 +private:
1.366 + //Handle to StdioSession
1.367 + RStdioSession iSession;
1.368 + TRedirConnState iStatus;
1.369 + RFastLock iLock;
1.370 + };
1.371 +
1.372 +
1.373 +NONSHARABLE_CLASS(CStdErrDesc) : public CFileDescBase
1.374 +
1.375 +/*
1.376 +client-side Standard Error desc class which will be used to put all stderr to RDebug::Printf
1.377 +@internalComponent
1.378 +*/
1.379 + {
1.380 +public:
1.381 + CStdErrDesc();
1.382 + virtual void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.383 + TInt WriteCompletion(TDes8& aDesc, TInt /*aStatus*/);
1.384 + virtual TInt Fcntl(TUint anArg, TUint aCmd);
1.385 + virtual TInt Type()
1.386 + {
1.387 + return EStdErrDesc;
1.388 + }
1.389 + };
1.390 +
1.391 +NONSHARABLE_CLASS(CFileDesc) : public CFileDescBase
1.392 +/*
1.393 +Abstractions for a plain file and a temporary file
1.394 +@internalComponent
1.395 +*/
1.396 + {
1.397 +public:
1.398 + CFileDesc();
1.399 + ~CFileDesc();
1.400 +
1.401 + void SetState(const TDes& params);
1.402 +
1.403 + TInt Open(RFs& aSession, const TDesC& aName, int mode, int perms);
1.404 + TInt LSeek(off_t& offset, int whence);
1.405 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.406 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.407 + TInt FStat(struct stat *st);
1.408 + void Sync(TRequestStatus &aStatus);
1.409 + TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.410 + TInt Fcntl(TUint anArg, TUint aCmd);
1.411 + static void MapStat(struct stat& st, const TTime& aModTime, TUint& aAttr, const mode_t aMode = S_IFREG);
1.412 + TInt Truncate(off_t anOffset);
1.413 + TInt SetAtt(TUint aSetAttMask, TUint aClearAttMask);
1.414 + TInt ProcessLockParams(FSIZE& pos, FSIZE &lock_len, TInt& lock_type, struct flock* anArg);
1.415 + inline int CreateLock()
1.416 + {
1.417 + return iLock.CreateLocal();
1.418 + }
1.419 +
1.420 + inline RFILE& FileHandle()
1.421 + {
1.422 + return iFile;
1.423 + }
1.424 +
1.425 + inline const FSIZE Offset() const
1.426 + {
1.427 + return iPos;
1.428 + }
1.429 +
1.430 + inline const FSIZE Size() const
1.431 + {
1.432 + return iSize;
1.433 + }
1.434 + inline void setSize(TUint32 param)
1.435 + {
1.436 + iSize = param;
1.437 + }
1.438 + inline const FSIZE Extent() const
1.439 + {
1.440 + return iExt;
1.441 + }
1.442 + virtual TInt Type()
1.443 + {
1.444 + return EFileDesc;
1.445 + }
1.446 +protected:
1.447 + virtual TInt FinalClose();
1.448 + TInt Alloc();
1.449 +private:
1.450 + TInt FileRead(TUint8* aPtr,TInt aLength);
1.451 + TInt FileWrite(TUint8* aPtr,TInt aLength);
1.452 + TInt Flush();
1.453 + TInt DoSync();
1.454 + TInt DoRead(TDes8& aDesc);
1.455 + TInt DoWrite(TDes8& aDesc);
1.456 + FSIZE Pos();
1.457 + FSIZE Ext();
1.458 +
1.459 +private:
1.460 + enum {EAlloc,EReading,EWriting};
1.461 + enum {EBufferSize = 0x600,EReadAhead = 0x200};
1.462 +protected:
1.463 + RFILE iFile;
1.464 + TInt16 iDrive; // for use with stat()
1.465 +private:
1.466 + TUint8 iState;
1.467 + TUint8* iBuffer;
1.468 + TUint8* iPtr;
1.469 + TUint8* iEnd;
1.470 +
1.471 + FSIZE iSize;
1.472 + FSIZE iPos;
1.473 + FSIZE iExt;
1.474 +
1.475 + //For locking the descriptor before any operation.
1.476 + //To make it thread safe.
1.477 + RFastLock iLock;
1.478 + friend class RFileDesTransferSession;
1.479 + friend class CFileDesTransferSession;
1.480 + };
1.481 +
1.482 +NONSHARABLE_CLASS(CTempFileDesc) : public CFileDesc
1.483 +/*
1.484 +@internalComponent
1.485 +*/
1.486 + {
1.487 +public:
1.488 + TInt Open(const wchar_t* aName, TInt mode);
1.489 + virtual TInt Type()
1.490 + {
1.491 + return EFileTempDesc;
1.492 + }
1.493 +protected:
1.494 + virtual TInt FinalClose();
1.495 +private:
1.496 + RFs iSession;
1.497 + TFileName iName;
1.498 + };
1.499 +
1.500 +/*
1.501 +Implements common functionality between CSocketDesc and CFileSocketDesc.
1.502 +Not meant to be instantaible.
1.503 +*/
1.504 +NONSHARABLE_CLASS(CSockDescBase) : public CFileDescBase
1.505 + {
1.506 +public:
1.507 + virtual TInt Socket(RSocketServ& aSs, int family, int style, int protocol);
1.508 + TInt Fcntl(TUint anArg, TUint aCmd);
1.509 + TInt FStat(struct stat *st);
1.510 + TInt FinalClose();
1.511 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.512 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.513 + void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus);
1.514 + void SendTo(TDes8& aDesc, TSockAddr& to, int flags, TRequestStatus& aStatus);
1.515 + TInt Poll(TUint aEvents);
1.516 + TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 aTimeout);
1.517 + void TweakWatchedEvents(TUint& events);
1.518 + TInt TweakReadyEvents(TInt errval);
1.519 + void CancelNotify();
1.520 + TInt Listen(TUint qSize);
1.521 + void ReadCancel();
1.522 + TInt ReadCompletion(TDes8& aBuf, TInt aStatus);
1.523 + void RecvFromCancel();
1.524 + void SendToCancel();
1.525 + void WriteCancel();
1.526 + TInt SockName(int anEnd, TSockAddr& anAddr);
1.527 + void Shutdown(TUint aHow,TRequestStatus& aStatus);
1.528 + TInt CompletionStatus(TInt& aLength, TInt aStatus);
1.529 + const TUint& GetSelectEvents()
1.530 + {
1.531 + iIoctlLock.Signal();
1.532 + return iSelectEvents();
1.533 + }
1.534 +
1.535 + inline TInt CreateLock()
1.536 + {
1.537 + TInt err = iIoctlLock.CreateLocal(1) || iReadLock.CreateLocal() || iWriteLock.CreateLocal();
1.538 + if (err != KErrNone)
1.539 + {
1.540 + // closes on unopened handles are safe
1.541 + iIoctlLock.Close();
1.542 + iReadLock.Close();
1.543 + iWriteLock.Close();
1.544 + }
1.545 + return err;
1.546 + }
1.547 +
1.548 + inline RSemaphore& GetIoctlLock()
1.549 + {
1.550 + return iIoctlLock;
1.551 + }
1.552 + inline TBool GetConnectionProgress()
1.553 + {
1.554 + return iConnectInProgress;
1.555 + }
1.556 +
1.557 + inline void SetConnectionProgress( TBool aInProgress )
1.558 + {
1.559 + iConnectInProgress = aInProgress;
1.560 + }
1.561 +
1.562 +protected:
1.563 + //rearrange these
1.564 + CSockDescBase():iAddrFamily(-1),iProtocol(KUndefinedProtocol),iIoctlFlag(EFalse),iCount(0)
1.565 + {
1.566 +
1.567 + }
1.568 + RSocket iSocket;
1.569 + TSockXfrLength iLength;
1.570 + TFileName iPath;
1.571 + TPckgBuf<TUint> iSelectEvents;
1.572 + TInt iAddrFamily;
1.573 + TInt iProtocol;
1.574 + TInt iStyle;
1.575 + // For preventing simultaneous ioctl calls.
1.576 + // No native support.
1.577 + RSemaphore iIoctlLock;
1.578 + // Is this required?
1.579 + TBool iIoctlFlag;
1.580 + // Safeguard against issue of a second Read/Write request while the first is pending.
1.581 + // The iReadLock also guards OpenUsingPreference
1.582 + //For locking the descriptor before any operation.
1.583 + //To make it thread safe.
1.584 + RFastLock iReadLock;
1.585 + RFastLock iWriteLock;
1.586 +
1.587 + //Flag to mark the connect status of a non-blocking socket as "in progress"
1.588 + //to prevent duplicate connection request
1.589 + TBool iConnectInProgress;
1.590 + volatile TInt iCount;
1.591 +protected:
1.592 +
1.593 + inline TInt isStream() const // inline, but private
1.594 + {
1.595 + return iStyle==SOCK_STREAM;
1.596 + }
1.597 + };
1.598 +
1.599 +NONSHARABLE_CLASS(CSocketDesc) : public CSockDescBase
1.600 +/*
1.601 +Abstraction for a socket
1.602 +@internalComponent
1.603 +*/
1.604 + {
1.605 +public:
1.606 + CSocketDesc();
1.607 + TInt Socket(RSocketServ& aSs, int family, int style, int protocol);
1.608 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.609 + TInt ReadCompletion (TDes8& /*aBuf*/, TInt aStatus);
1.610 + void ReadCancel();
1.611 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.612 + void WriteCancel();
1.613 + void Sync(TRequestStatus& aStatus);
1.614 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.615 + TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.616 + void IoctlCancel();
1.617 +
1.618 + void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus);
1.619 + void RecvFromCancel();
1.620 + void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen, int flags, TRequestStatus& aStatus);
1.621 +
1.622 + void SendToCancel();
1.623 +
1.624 + void Shutdown(TUint aHow,TRequestStatus& aStatus);
1.625 + void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs,TSockAddr *aAddr);
1.626 + void AcceptCancel();
1.627 + void Connect(const struct sockaddr* aAddr,unsigned long size,TRequestStatus& aStatus);
1.628 + void ConnectCancel();
1.629 +
1.630 + TInt Bind(const struct sockaddr* addr, unsigned long size);
1.631 + TInt Listen(TUint qSize);
1.632 + TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize);
1.633 + TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption);
1.634 + TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption);
1.635 + TInt Fcntl(TUint anArg, TUint aCmd);
1.636 +
1.637 + TInt Poll(TPollMode aMode,TBool& aReadyStatus,TInt& aErrno);
1.638 + TInt Poll(TUint aEvents);
1.639 + void CancelNotify();
1.640 + void TempClose();
1.641 +
1.642 + void SetFids(void *aFids);
1.643 + virtual TInt Type()
1.644 + {
1.645 + return ESocketDesc;
1.646 + }
1.647 +
1.648 +protected:
1.649 + TInt FinalClose();
1.650 +private:
1.651 +
1.652 + TInt GetInterfaceIndex(TUint32 aAddr);
1.653 + TInt GetInterfaceList(void *aParam);
1.654 + TInt GetActiveInterface( void *aParam);
1.655 + TInt GetInterfaceIndexByName(void *aParam);
1.656 + TInt GetActiveInterfaceList(void *aParam);
1.657 + TInt SetInterfaceByName(void *aParam);
1.658 + TInt StartInterface(void *aParam);
1.659 + TInt StartActiveInterface(void *aParam);
1.660 + TInt StopInterface(void *aParam);
1.661 + TInt OpenUsingPreference();
1.662 + void AccessPointListL(CArrayFixFlat<TAccessPointRecord> *&aRecordPtr, TInt &aLength);
1.663 + void AccessPointCountL(TInt &aCount);
1.664 + void ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord);
1.665 + void OpenIapTableLC(CCommsDatabase **aIapDatabase, CCommsDbTableView **aView);
1.666 + TInt ActiveConnectionCount(TInt &aCount);
1.667 + TInt ActiveConnectionListL(CArrayFixFlat<TAccessPointRecord> *aRecordPtr, TInt &aLength);
1.668 + TInt GetRConnectionDetails(RConnection *aRc, TAccessPointRecord &aApr);
1.669 + TInt StartConnection(void *aParam);
1.670 + TInt GetConnectionPreference(TCommDbConnPref &aApr);
1.671 + void GetIapDetailsByNameL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName, TAccessPointRecord &aRecord);
1.672 + void StopSubConnection();
1.673 + void StopConnection();
1.674 + TInt StartSubConnection(void *aParam);
1.675 + TInt GetInterface(void *Param, TInt aType);
1.676 + TInt GetInterafceNumber(void *aParam);
1.677 + TInt GetIpAddress( void *aParam );
1.678 +
1.679 + TInt RouteRequest(TInt aReq, void *aParam);
1.680 + TInt GetInterfaceHWAddress(void *aParam);
1.681 +
1.682 + TInt ConvertRtEntry(TSoInetRouteInfo& aRouteInfo, struct rtentry *aRouteEntry);
1.683 + TInt ConvertSockAddr(TInetAddr& aInetAddr, struct sockaddr_in *aSockAddr);
1.684 +
1.685 + TInt GetInterfaceByName(const TDesC& aIfName, TPckgBuf<TSoInetInterfaceInfo>& aIface);
1.686 + TInt Copy(TInetAddr& aDest, TInetAddr& aSrc);
1.687 +
1.688 + TInt GetRemoteIpAddress( void *aParam );
1.689 + TInt GetInterafceParamInfo( void *aParam,TInt aType);
1.690 + void FindConnectionDetailsL(CArrayFixFlat<TAccessPointRecord>*& aRecordPtr, TInt& aCount);
1.691 + void FindConnectionInfoL(TAccessPointRecord &aRecord,char *ptr);
1.692 + TInt GetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
1.693 + TInt SetInterafceParamInfo( void *aParam,TInt aType);
1.694 + TInt SetInterfaceDetails( void *aParam ,TInt aFlag, TInt aType );
1.695 +
1.696 + TInt maybe_reopen_socket()
1.697 + {
1.698 + TInt err = KErrNone;
1.699 + if (!__e32_atomic_load_acq32(&iSocketPtr))
1.700 + {
1.701 + iReadLock.Wait();
1.702 + if (!iSocketPtr)
1.703 + {
1.704 + err = OpenUsingPreference();
1.705 + }
1.706 + iReadLock.Signal();
1.707 + }
1.708 + return err;
1.709 + }
1.710 +
1.711 + enum InterfaceType
1.712 + {
1.713 + EACCESS_POINT,
1.714 + EACTIVE_CONNECTION,
1.715 + EACTIVE_GETIP,
1.716 + EACCESS_GETMETRIC,
1.717 + EACCESS_GETMTU,
1.718 + EACCESS_GETNETMASK,
1.719 + EACCESS_GETBROADCAST,
1.720 + EACCESS_GETPHYSADDR,
1.721 + EACCESS_GETFLAGS,
1.722 + EACCESS_SETMETRIC,
1.723 + EACCESS_SETMTU,
1.724 + EACCESS_SETFLAGS,
1.725 + EACCESS_SETPHYSADDR,
1.726 + EACTIVE_SETIP,
1.727 + EACCESS_SETNETMASK,
1.728 + EACCESS_SETBROADCAST
1.729 + };
1.730 +
1.731 + TPtr8 iIoctlBuf;
1.732 + RSocket *iSocketPtr;
1.733 + TAccessPointRecord iConnPref;
1.734 + RConnection iConnection;
1.735 + RConnection *iConnectionPtr;
1.736 + RSubConnection iSubConnection;
1.737 + RSubConnection *iSubConnectionPtr;
1.738 + TInt iRConnectionIndex;
1.739 + RSocketServ *iSockServPtr;
1.740 + void *iFids;
1.741 +
1.742 + };
1.743 +
1.744 +
1.745 +class CNotifier;
1.746 +
1.747 +NONSHARABLE_CLASS(CSerialDesc) : public CFileDescBase
1.748 +/*
1.749 +@internalComponent
1.750 +*/
1.751 + {
1.752 +
1.753 + friend class CNotifier;
1.754 +
1.755 + public:
1.756 + CSerialDesc() : CFileDescBase(), iReadThreshold(-1), iRequestedSignals(0),
1.757 + iNotifyStatus(NULL), iNotifyParamPtr(NULL) {}
1.758 +
1.759 + TInt Open(const wchar_t* name, int mode, int perms);
1.760 + TInt FinalClose();
1.761 +
1.762 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.763 + void ReadCancel();
1.764 +
1.765 + TInt& TimeoutValue() const;
1.766 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.767 + TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
1.768 +
1.769 +
1.770 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.771 + TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.772 + void IoctlCancel();
1.773 +
1.774 + TBool TimedRead();
1.775 + void UserClose();
1.776 + virtual TInt Type()
1.777 + {
1.778 + return ESerialDesc;
1.779 + }
1.780 +
1.781 +protected:
1.782 +
1.783 +private:
1.784 +
1.785 + void NotifyDataAvailable(TRequestStatus& aStatus);
1.786 + void NotifyOutputEmpty(TRequestStatus& aStatus);
1.787 + void NotifyBreak(TRequestStatus& aStatus);
1.788 + void NotifyWriteErrors(TRequestStatus& aStatus, TUint* aRequestParams, TUint aSignalsMask);
1.789 + void NotifySignalChange(TRequestStatus& iStatus, TUint& aRequestParam, TUint aSignalsMask);
1.790 + void NotifyDataAvailableCancel();
1.791 + void NotifyOutputEmptyCancel();
1.792 + void NotifyBreakCancel();
1.793 + void NotifyWriteErrorsCancel();
1.794 + void NotifySignalChangeCancel();
1.795 + void Notify(TInt aVal); //complete the notify request
1.796 + TInt NotifiesSupported(); //return the notifies supported at the moment
1.797 + TBool RequestedNotifiesSupported(TInt aRequested); //see if the notifies requested are supported
1.798 + void CancelNotifiers(const CNotifier* aCompletedNotifier); //cancel them all apart from the passed one
1.799 + TUint Signals();
1.800 +
1.801 + TInt ReadCompletion (TDes8& aBuf, TInt aStatus);
1.802 +
1.803 + TInt iReadThreshold;
1.804 + RComm iCommPort;
1.805 +
1.806 + TInt iRequestedSignals;
1.807 + TRequestStatus* iNotifyStatus;
1.808 + TUint* iNotifyParamPtr;
1.809 + TUint* iRequestDataPtr;
1.810 +
1.811 + CNotifier* iDataAvailableNotifier;
1.812 + CNotifier* iOutputEmptyNotifier;
1.813 + CNotifier* iBreakNotifier;
1.814 + CNotifier* iErrorsNotifier;
1.815 + CNotifier* iSignalsNotifier;
1.816 +
1.817 + };
1.818 +
1.819 +
1.820 +NONSHARABLE_CLASS(CPipeDescBase) : public CFileDescBase
1.821 +/*
1.822 +Base class with the RPipe handle and common methods
1.823 +@internalComponent
1.824 +*/
1.825 + {
1.826 +public:
1.827 + CPipeDescBase(const TUint16 aMode = 0) : CFileDescBase()
1.828 + {
1.829 + iFdAttrib |= KPipeFd;
1.830 + if (aMode & O_NONBLOCK)
1.831 + {
1.832 + iFcntlFlag |= O_NONBLOCK;
1.833 + }
1.834 + }
1.835 +
1.836 + TInt Fcntl(TUint anArg, TUint aCmd);
1.837 + TInt FStat(struct stat *st);
1.838 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.839 + TInt FinalClose();
1.840 +
1.841 + RPipe& Handle()
1.842 + {
1.843 + return iHandle;
1.844 + }
1.845 +
1.846 + TUint& FcntlFlag()
1.847 + {
1.848 + return iFcntlFlag;
1.849 + }
1.850 +
1.851 + TUint32& FDAttrib()
1.852 + {
1.853 + return iFdAttrib;
1.854 + }
1.855 + virtual TInt Type()
1.856 + {
1.857 + return EPipeDesc;
1.858 + }
1.859 +
1.860 +protected:
1.861 + RPipe iHandle;
1.862 + };
1.863 +
1.864 +NONSHARABLE_CLASS(CPipeReadDesc) : public CPipeDescBase
1.865 +/*
1.866 +Handle to the read-end of an RPipe object.
1.867 +@internalComponent
1.868 +*/
1.869 + {
1.870 +public:
1.871 + CPipeReadDesc(const TUint16 aMode = 0) : CPipeDescBase(aMode)
1.872 + {
1.873 + iFcntlFlag |= O_RDONLY;
1.874 + }
1.875 +
1.876 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.877 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.878 + TInt Poll(TUint aEvents);
1.879 + TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 /*timeout*/);
1.880 + TInt TweakReadyEvents(TInt errval);
1.881 + void CancelNotify();
1.882 +
1.883 +protected:
1.884 + TInt DoRead(TDes8& aDesc);
1.885 + };
1.886 +
1.887 +NONSHARABLE_CLASS(CPipeWriteDesc) : public CPipeDescBase
1.888 +/*
1.889 +Handle to the write-end of an RPipe object.
1.890 +@internalComponent
1.891 +*/
1.892 + {
1.893 +public:
1.894 + CPipeWriteDesc(const TUint16 aMode = 0) : CPipeDescBase(aMode)
1.895 + {
1.896 + iFcntlFlag |= O_WRONLY;
1.897 + }
1.898 +
1.899 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.900 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.901 + TInt Poll(TUint aEvents);
1.902 + TInt NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout);
1.903 + TInt TweakReadyEvents(TInt errval);
1.904 + void CancelNotify();
1.905 +
1.906 +protected:
1.907 + TInt DoWrite(TDes8& aDesc);
1.908 + };
1.909 +NONSHARABLE_CLASS(CFileSocketDesc) : public CSockDescBase
1.910 +/*
1.911 +Class representing AF_UNIX socket descriptors
1.912 +Implemented using 2 FIFOs
1.913 +@internalComponent
1.914 +*/
1.915 + {
1.916 +public:
1.917 + CFileSocketDesc(const TUint16 aMode = 0)
1.918 + {
1.919 + if (aMode & O_NONBLOCK)
1.920 + {
1.921 + iFcntlFlag |= O_NONBLOCK;
1.922 + }
1.923 + iFcntlFlag |= O_RDWR;
1.924 + iPath.Zero();
1.925 + }
1.926 +
1.927 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.928 + TInt FinalClose();
1.929 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.930 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.931 + void RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus);
1.932 + void SendTo(TDes8& aDesc, const struct sockaddr* anAddr, unsigned long aAddrLen, int flags, TRequestStatus& aStatus);
1.933 + TInt Listen(TUint qSize);
1.934 + TInt GetSockOpt(TInt anOptionName,TInt anOptionLevel,TDes8& anOption);
1.935 + TInt SetSockOpt(TInt anOptionName,TInt anOptionLevel,TDesC8& anOption);
1.936 + TInt Bind(const struct sockaddr* addr, unsigned long size);
1.937 + void Connect(const struct sockaddr* aAddr,unsigned long size, TRequestStatus& aStatus);
1.938 + void Accept(CFileDescBase*& aNewSocket, TRequestStatus& aStatus, RSocketServ& aSs, TSockAddr *);
1.939 + TInt Socket(RSocketServ& aSs, int family, int style, int protocol);
1.940 + TInt SockName(int anEnd, struct sockaddr* anAddr,unsigned long* aSize);
1.941 + void AcceptCancel();
1.942 + void ConnectCancel();
1.943 +
1.944 + TUint& FcntlFlag()
1.945 + {
1.946 + return iFcntlFlag;
1.947 + }
1.948 +
1.949 + TUint32& FDAttrib()
1.950 + {
1.951 + return iFdAttrib;
1.952 + }
1.953 + virtual TInt Type()
1.954 + {
1.955 + return EFileSocketDesc;
1.956 + }
1.957 +
1.958 + TInt GetLocalSockAddrByPort(struct sockaddr_un* aAddr,unsigned long* aAddrLen,TUint aPortNum);
1.959 + TInt GetLocalSockPortByPath(const struct sockaddr_un* aAddr,unsigned long aAddrLen,TUint& aPortNum);
1.960 +
1.961 +private:
1.962 + TInt ValidateAddress(const struct sockaddr_un* aAddr,unsigned long* aAddrLen);
1.963 + TInt RemoveLocalSockAddr();
1.964 +private:
1.965 + TBuf8<KMaxFileName> iPath;
1.966 + RFastLock iReadLock;
1.967 + RFastLock iWriteLock;
1.968 + class TAutoFastLock
1.969 + {
1.970 + public:
1.971 + TAutoFastLock(RFastLock &aLock):iAutoLock(aLock)
1.972 + {
1.973 + iAutoLock.Wait() ;
1.974 + }
1.975 + ~TAutoFastLock()
1.976 + {
1.977 + iAutoLock.Signal() ;
1.978 + }
1.979 + private:
1.980 + RFastLock &iAutoLock;
1.981 + };
1.982 + };
1.983 +
1.984 +NONSHARABLE_CLASS(CDirectoryDesc) : public CFileDescBase
1.985 +/*
1.986 +Abstractions for a directory
1.987 +@internalComponent
1.988 +*/
1.989 + {
1.990 +public:
1.991 + CDirectoryDesc();
1.992 + ~CDirectoryDesc();
1.993 +
1.994 + TInt Open(RFs& aSession, const TDesC& aName, int mode, int perms);
1.995 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.996 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.997 + TInt Fcntl(TUint anArg, TUint aCmd);
1.998 + TInt LSeek(off_t& offset, int whence);
1.999 + TInt FStat(struct stat *st);
1.1000 + //Get the Name of the directory
1.1001 + inline const wchar_t* GetDirName()
1.1002 + {
1.1003 + return (const wchar_t*)iDirName.Ptr();
1.1004 + }
1.1005 + virtual TInt Type()
1.1006 + {
1.1007 + return EDirDesc;
1.1008 + }
1.1009 +
1.1010 +private:
1.1011 + RDir iDir;
1.1012 + //Name of the directory
1.1013 + TFileName iDirName;
1.1014 + };
1.1015 +
1.1016 +#ifdef SYMBIAN_OE_LIBRT
1.1017 +NONSHARABLE_CLASS(CSharedMemDesc) : public CFileDescBase
1.1018 +/*
1.1019 +Abstractions for shared memory
1.1020 +@internalComponent
1.1021 +*/
1.1022 + {
1.1023 +public:
1.1024 + CSharedMemDesc();
1.1025 + ~CSharedMemDesc();
1.1026 +
1.1027 + TInt Open(const wchar_t* aName, int mode, int perms);
1.1028 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.1029 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.1030 + TInt Fcntl(TUint anArg, TUint aCmd);
1.1031 + TInt FStat(struct stat *st);
1.1032 + TInt LSeek(off_t& offset, int whence);
1.1033 +private:
1.1034 + TInt ShmRead(TUint8* aPtr,TInt aLength);
1.1035 + TInt ShmWrite(TUint8* aPtr,TInt aLength);
1.1036 + TInt DoShmRead(TDes8& aDesc);
1.1037 + TInt DoShmWrite(TDes8& aDesc);
1.1038 + TInt Pos();
1.1039 + TInt Ext();
1.1040 +protected:
1.1041 + TInt FinalClose();
1.1042 +private:
1.1043 + RFastLock iLock;
1.1044 + void* iPtr;
1.1045 + TInt iSize;
1.1046 + TInt iPos;
1.1047 + TInt iExt;
1.1048 + TInt iPerms;
1.1049 + TInt iKey;
1.1050 + };
1.1051 +#endif //SYMBIAN_OE_LIBRT
1.1052 +#endif // !_FDESC_H