00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "cobain.h"
00026 #include "clientsession.h"
00027
00028 RCobainSocket::RCobainSocket(RCobainClientSession &aSession,
00029 TInt aId)
00030 : CActive(CActive::EPriorityStandard),
00031 iSession(aSession),
00032 iId(aId),
00033 iIsClosed(EFalse)
00034 {
00035 CActiveScheduler::Add(this);
00036 }
00037
00038 EXPORT_C RCobainSocket::~RCobainSocket()
00039 {
00040
00041 Close(ETrue);
00042
00043
00044 iSocketListener = NULL;
00045 }
00046
00047 EXPORT_C void RCobainSocket::SendL(const TDesC8 *aBuffer)
00048 {
00049 if( iIsClosed ) {
00050 User::Leave(KErrCobainSocketClosed);
00051 }
00052
00053 TInt ret = iSession.Send(iId, aBuffer);
00054 if( (iSocketListener != NULL) && (ret != KErrNone) ) {
00055 iSocketListener->SocketError(ret, this);
00056 }
00057 }
00058
00059 EXPORT_C void RCobainSocket::Close(TBool aImmediately)
00060 {
00061 if( iIsClosed ) {
00062
00063 return;
00064 }
00065
00066
00067 iSession.CloseSocket(iId, aImmediately);
00068
00069
00070 Cancel();
00071
00072
00073 iIsClosed = ETrue;
00074 }
00075
00076 EXPORT_C void RCobainSocket::SetSocketListener(MSocketListener *aSocketListener)
00077 {
00078 __ASSERT_ALWAYS(aSocketListener != NULL,
00079 User::Panic(KCobainSocketPanic, KErrCobainSocketNullSocketListener));
00080
00081
00082 Cancel();
00083
00084 iSocketListener = aSocketListener;
00085
00086
00087 Receive();
00088 }
00089
00090
00091 void RCobainSocket::Receive()
00092 {
00093 Log::Print(_L("RCobainSocket::Receive()"));
00094
00095 iSession.Receive(iId, &iRecvBuf, iStatus);
00096 SetActive();
00097
00098 Log::Print(_L("RCobainSocket::Receive() exiting"));
00099 }
00100
00102
00104
00105 void RCobainSocket::DoCancel()
00106 {
00107 }
00108
00109
00110 void RCobainSocket::RunL()
00111 {
00112 Log::Print(_L("RCobainSocket::RunL()"));
00113
00114
00115 if( iSocketListener == NULL ) {
00116 return;
00117 }
00118
00119 TInt status = iStatus.Int();
00120 if( status != KErrNone ) {
00121
00122 if( status == KErrDisconnected ) {
00123
00124 Close();
00125 iSocketListener->SocketDisconnected(this);
00126 } else {
00127 iSocketListener->SocketError(status, this);
00128 }
00129 } else {
00130
00131 iSocketListener->Data(iRecvBuf, this);
00132
00133
00134 Receive();
00135 }
00136
00137 Log::Print(_L("RCobainSocket::RunL() exiting"));
00138 }
00139