mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
first checked in. Untested since I can't get packets to the device
from outside the carrier's firewall.
This commit is contained in:
parent
54fce74a1f
commit
bc7f858615
2 changed files with 219 additions and 0 deletions
75
symbian/inc/symrsock.h
Normal file
75
symbian/inc/symrsock.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
||||
/*
|
||||
* Copyright 2005 by Eric House (fixin@peak.org). (based on sample
|
||||
* app helloworldbasic "Copyright (c) 2002, Nokia. All rights
|
||||
* reserved.")
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
||||
#ifndef _SYMRSOCK_H_
|
||||
#define _SYMRSOCK_H_
|
||||
|
||||
#include <es_sock.h>
|
||||
#include <in_sock.h>
|
||||
#include "comms.h"
|
||||
|
||||
const TInt KMaxRcvMsgLen = 512;
|
||||
|
||||
class CReadSocket : public CActive {
|
||||
|
||||
public:
|
||||
typedef void (*ReadNotifyCallback)( const TDesC8* aBuf,
|
||||
void *closure );
|
||||
|
||||
static CReadSocket* NewL( ReadNotifyCallback aGotData,
|
||||
void* aCallbackClosure );
|
||||
~CReadSocket();
|
||||
|
||||
void SetListenPort( TInt aPort );
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
protected:
|
||||
void RunL(); /* from CActive */
|
||||
void DoCancel(); /* from CActive */
|
||||
|
||||
private:
|
||||
CReadSocket( ReadNotifyCallback aGotData, void* aCallbackClosure );
|
||||
void ConstructL();
|
||||
void RequestRecv();
|
||||
void Bind();
|
||||
|
||||
enum TReadState {
|
||||
ENotReading
|
||||
,EReading
|
||||
};
|
||||
|
||||
TReadState iReadState;
|
||||
ReadNotifyCallback iGotData;
|
||||
void* iCallbackClosure;
|
||||
RSocket iListenSocket;
|
||||
TInt iPort;
|
||||
TBuf8<KMaxRcvMsgLen> iInBuf;
|
||||
TSockXfrLength iReadLength;
|
||||
RSocketServ iSocketServer;
|
||||
TInetAddr iRecvAddr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* XWFEATURE_STANDALONE_ONLY */
|
144
symbian/src/symrsock.cpp
Normal file
144
symbian/src/symrsock.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
||||
/*
|
||||
* Copyright 2005 by Eric House (fixin@peak.org). (based on sample
|
||||
* app helloworldbasic "Copyright (c) 2002, Nokia. All rights
|
||||
* reserved.")
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
||||
#include "symrsock.h"
|
||||
|
||||
/*static*/ CReadSocket*
|
||||
CReadSocket::NewL( ReadNotifyCallback aCallback, void* aCallbackClosure )
|
||||
{
|
||||
CReadSocket* self = new (ELeave) CReadSocket( aCallback, aCallbackClosure );
|
||||
CleanupStack::PushL( self );
|
||||
self->ConstructL();
|
||||
CleanupStack::Pop( self );
|
||||
return self;
|
||||
}
|
||||
|
||||
CReadSocket::CReadSocket( ReadNotifyCallback aGotData, void* aCallbackClosure )
|
||||
: iGotData(aGotData)
|
||||
, iCallbackClosure(aCallbackClosure)
|
||||
, iReadState(ENotReading)
|
||||
, iPort(0)
|
||||
, CActive(EPriorityStandard)
|
||||
{
|
||||
iInBuf.SetLength(0);
|
||||
}
|
||||
|
||||
CReadSocket::~CReadSocket()
|
||||
{
|
||||
Cancel();
|
||||
iSocketServer.Close();
|
||||
}
|
||||
|
||||
void
|
||||
CReadSocket::ConstructL()
|
||||
{
|
||||
CActiveScheduler::Add( this );
|
||||
TInt err = iSocketServer.Connect();
|
||||
XP_LOGF( "iSocketServer.Connect => %d", err );
|
||||
|
||||
err = iListenSocket.Open( iSocketServer, KAfInet,
|
||||
KSockDatagram, KProtocolInetUdp );
|
||||
XP_LOGF( "iListenSocket.Open => %d", err );
|
||||
|
||||
if ( iPort != 0 ) {
|
||||
Bind();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CReadSocket::Bind()
|
||||
{
|
||||
XP_ASSERT( iPort != 0 );
|
||||
TSockAddr iSockAddress( KProtocolInetUdp );
|
||||
iSockAddress.SetPort( iPort );
|
||||
|
||||
TInt err = iListenSocket.Bind( iSockAddress );
|
||||
XP_LOGF( "iListenSocket.Bind => %d", err );
|
||||
} /* Bind */
|
||||
|
||||
void
|
||||
CReadSocket::SetListenPort( TInt aPort )
|
||||
{
|
||||
XP_LOGF( "SetListenPort(%d)", aPort );
|
||||
if ( aPort != iPort ) {
|
||||
TBool wasActive = iReadState == EReading && IsActive();
|
||||
if ( wasActive ) {
|
||||
Cancel(); /* stop anything ongoing */
|
||||
}
|
||||
iPort = aPort;
|
||||
Bind();
|
||||
if ( wasActive ) {
|
||||
RequestRecv();
|
||||
}
|
||||
}
|
||||
} /* SetListenPort */
|
||||
|
||||
void
|
||||
CReadSocket::RequestRecv()
|
||||
{
|
||||
XP_ASSERT( !IsActive() );
|
||||
|
||||
XP_LOGF( "calling iListenSocket.RecvFrom" );
|
||||
iListenSocket.RecvFrom( iInBuf, iRecvAddr, 0, iStatus );
|
||||
|
||||
iReadState = EReading;
|
||||
SetActive();
|
||||
} /* RequestRead */
|
||||
|
||||
void
|
||||
CReadSocket::RunL()
|
||||
{
|
||||
XP_ASSERT( iStatus.Int() == KErrNone );
|
||||
XP_ASSERT( iReadState == EReading );
|
||||
if ( iStatus.Int() == KErrNone ) {
|
||||
XP_LOGF( "SUCCESS: packet received!" );
|
||||
(*iGotData)( &iInBuf, iCallbackClosure );
|
||||
iInBuf.SetLength(0);
|
||||
}
|
||||
iReadState = ENotReading;
|
||||
|
||||
RequestRecv(); /* We just keep listening... */
|
||||
} /* RunL */
|
||||
|
||||
void
|
||||
CReadSocket::DoCancel()
|
||||
{
|
||||
if ( iReadState == EReading ) {
|
||||
iListenSocket.CancelRecv();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CReadSocket::Start()
|
||||
{
|
||||
if ( !IsActive() ) {
|
||||
RequestRecv();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CReadSocket::Stop()
|
||||
{
|
||||
Cancel();
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue