1
/* $Id: sock_symbian.cpp 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <pj/addr_resolv.h>
22
#include <pj/assert.h>
25
#include <pj/string.h>
26
#include <pj/unicode.h>
28
#include "os_symbian.h"
34
const pj_uint16_t PJ_AF_UNSPEC = KAFUnspec;
35
const pj_uint16_t PJ_AF_UNIX = 0xFFFF;
36
const pj_uint16_t PJ_AF_INET = KAfInet;
37
const pj_uint16_t PJ_AF_INET6 = KAfInet6;
38
const pj_uint16_t PJ_AF_PACKET = 0xFFFF;
39
const pj_uint16_t PJ_AF_IRDA = 0xFFFF;
42
* Socket types conversion.
43
* The values here are indexed based on pj_sock_type
45
const pj_uint16_t PJ_SOCK_STREAM= KSockStream;
46
const pj_uint16_t PJ_SOCK_DGRAM = KSockDatagram;
47
const pj_uint16_t PJ_SOCK_RAW = 0xFFFF;
48
const pj_uint16_t PJ_SOCK_RDM = 0xFFFF;
50
/* we don't support setsockopt(), these are just dummy values */
51
const pj_uint16_t PJ_SOL_SOCKET = 0xFFFF;
52
const pj_uint16_t PJ_SOL_IP = 0xFFFF;
53
const pj_uint16_t PJ_SOL_TCP = 0xFFFF;
54
const pj_uint16_t PJ_SOL_UDP = 0xFFFF;
55
const pj_uint16_t PJ_SOL_IPV6 = 0xFFFF;
56
const pj_uint16_t PJ_SO_NOSIGPIPE = 0xFFFF;
59
const pj_uint16_t PJ_IP_TOS = 0;
60
const pj_uint16_t PJ_IPTOS_LOWDELAY = 0;
61
const pj_uint16_t PJ_IPTOS_THROUGHPUT = 0;
62
const pj_uint16_t PJ_IPTOS_RELIABILITY = 0;
63
const pj_uint16_t PJ_IPTOS_MINCOST = 0;
66
const pj_uint16_t PJ_TCP_NODELAY = 0xFFFF;
67
const pj_uint16_t PJ_SO_REUSEADDR = 0xFFFF;
68
const pj_uint16_t PJ_SO_PRIORITY = 0xFFFF;
70
/* ioctl() is also not supported. */
71
const pj_uint16_t PJ_SO_TYPE = 0xFFFF;
72
const pj_uint16_t PJ_SO_RCVBUF = 0xFFFF;
73
const pj_uint16_t PJ_SO_SNDBUF = 0xFFFF;
75
/* IP multicast is also not supported. */
76
const pj_uint16_t PJ_IP_MULTICAST_IF = 0xFFFF;
77
const pj_uint16_t PJ_IP_MULTICAST_TTL = 0xFFFF;
78
const pj_uint16_t PJ_IP_MULTICAST_LOOP = 0xFFFF;
79
const pj_uint16_t PJ_IP_ADD_MEMBERSHIP = 0xFFFF;
80
const pj_uint16_t PJ_IP_DROP_MEMBERSHIP = 0xFFFF;
83
const int PJ_MSG_OOB = 0;
84
const int PJ_MSG_PEEK = KSockReadPeek;
85
const int PJ_MSG_DONTROUTE = 0;
87
/////////////////////////////////////////////////////////////////////////////
89
// CPjSocket implementation.
90
// (declaration is in os_symbian.h)
93
CPjSocket::~CPjSocket()
100
// Create socket reader.
101
CPjSocketReader *CPjSocket::CreateReader(unsigned max_len)
103
pj_assert(sockReader_ == NULL);
104
return sockReader_ = CPjSocketReader::NewL(*this, max_len);
107
// Delete socket reader when it's not wanted.
108
void CPjSocket::DestroyReader()
111
sockReader_->Cancel();
118
/////////////////////////////////////////////////////////////////////////////
120
// CPjSocketReader implementation
121
// (declaration in os_symbian.h)
125
CPjSocketReader::CPjSocketReader(CPjSocket &sock)
126
: CActive(EPriorityStandard),
127
sock_(sock), buffer_(NULL, 0), readCb_(NULL), key_(NULL)
132
void CPjSocketReader::ConstructL(unsigned max_len)
134
isDatagram_ = sock_.IsDatagram();
136
TUint8 *ptr = new TUint8[max_len];
137
buffer_.Set(ptr, 0, (TInt)max_len);
138
CActiveScheduler::Add(this);
141
CPjSocketReader *CPjSocketReader::NewL(CPjSocket &sock, unsigned max_len)
143
CPjSocketReader *self = new (ELeave) CPjSocketReader(sock);
144
CleanupStack::PushL(self);
145
self->ConstructL(max_len);
146
CleanupStack::Pop(self);
152
CPjSocketReader::~CPjSocketReader()
154
const TUint8 *data = buffer_.Ptr();
158
void CPjSocketReader::StartRecv(void (*cb)(void *key),
163
StartRecvFrom(cb, key, aDesc, flags, NULL);
166
void CPjSocketReader::StartRecvFrom(void (*cb)(void *key),
175
if (aDesc == NULL) aDesc = &buffer_;
176
if (fromAddr == NULL) fromAddr = &recvAddr_;
178
sock_.Socket().RecvFrom(*aDesc, *fromAddr, flags, iStatus);
182
void CPjSocketReader::DoCancel()
184
sock_.Socket().CancelRecv();
187
void CPjSocketReader::RunL()
189
void (*old_cb)(void *key) = readCb_;
190
void *old_key = key_;
200
// Append data to aDesc, up to aDesc's maximum size.
201
// If socket is datagram based, buffer_ will be clared.
202
void CPjSocketReader::ReadData(TDes8 &aDesc, TInetAddr *addr)
207
if (buffer_.Length() == 0)
210
TInt size_to_copy = aDesc.MaxLength() - aDesc.Length();
211
if (size_to_copy > buffer_.Length())
212
size_to_copy = buffer_.Length();
214
aDesc.Append(buffer_.Ptr(), size_to_copy);
219
buffer_.Delete(0, size_to_copy);
227
/////////////////////////////////////////////////////////////////////////////
229
// PJLIB's sock.h implementation
233
* Convert 16-bit value from network byte order to host byte order.
235
PJ_DEF(pj_uint16_t) pj_ntohs(pj_uint16_t netshort)
237
#if PJ_IS_LITTLE_ENDIAN
238
return pj_swap16(netshort);
245
* Convert 16-bit value from host byte order to network byte order.
247
PJ_DEF(pj_uint16_t) pj_htons(pj_uint16_t hostshort)
249
#if PJ_IS_LITTLE_ENDIAN
250
return pj_swap16(hostshort);
257
* Convert 32-bit value from network byte order to host byte order.
259
PJ_DEF(pj_uint32_t) pj_ntohl(pj_uint32_t netlong)
261
#if PJ_IS_LITTLE_ENDIAN
262
return pj_swap32(netlong);
269
* Convert 32-bit value from host byte order to network byte order.
271
PJ_DEF(pj_uint32_t) pj_htonl(pj_uint32_t hostlong)
273
#if PJ_IS_LITTLE_ENDIAN
274
return pj_swap32(hostlong);
281
* Convert an Internet host address given in network byte order
282
* to string in standard numbers and dots notation.
284
PJ_DEF(char*) pj_inet_ntoa(pj_in_addr inaddr)
286
static char str8[PJ_INET_ADDRSTRLEN];
287
TBuf<PJ_INET_ADDRSTRLEN> str16(0);
289
/* (Symbian IP address is in host byte order) */
290
TInetAddr temp_addr((TUint32)pj_ntohl(inaddr.s_addr), (TUint)0);
291
temp_addr.Output(str16);
293
return pj_unicode_to_ansi((const wchar_t*)str16.PtrZ(), str16.Length(),
298
* This function converts the Internet host address cp from the standard
299
* numbers-and-dots notation into binary data and stores it in the structure
300
* that inp points to.
302
PJ_DEF(int) pj_inet_aton(const pj_str_t *cp, struct pj_in_addr *inp)
304
enum { MAXIPLEN = PJ_INET_ADDRSTRLEN };
306
/* Initialize output with PJ_INADDR_NONE.
307
* Some apps relies on this instead of the return value
308
* (and anyway the return value is quite confusing!)
310
inp->s_addr = PJ_INADDR_NONE;
313
* this function might be called with cp->slen >= 16
314
* (i.e. when called with hostname to check if it's an IP addr).
316
PJ_ASSERT_RETURN(cp && cp->slen && inp, 0);
317
if (cp->slen >= 16) {
321
char tempaddr8[MAXIPLEN];
322
pj_memcpy(tempaddr8, cp->ptr, cp->slen);
323
tempaddr8[cp->slen] = '\0';
325
wchar_t tempaddr16[MAXIPLEN];
326
pj_ansi_to_unicode(tempaddr8, pj_ansi_strlen(tempaddr8),
327
tempaddr16, sizeof(tempaddr16));
329
TBuf<MAXIPLEN> ip_addr((const TText*)tempaddr16);
333
if (addr.Input(ip_addr) == KErrNone) {
334
/* Success (Symbian IP address is in host byte order) */
335
inp->s_addr = pj_htonl(addr.Address());
344
* Convert text to IPv4/IPv6 address.
346
PJ_DEF(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst)
348
char tempaddr[PJ_INET6_ADDRSTRLEN];
350
PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL);
351
PJ_ASSERT_RETURN(src && src->slen && dst, PJ_EINVAL);
353
/* Initialize output with PJ_IN_ADDR_NONE for IPv4 (to be
354
* compatible with pj_inet_aton()
356
if (af==PJ_AF_INET) {
357
((pj_in_addr*)dst)->s_addr = PJ_INADDR_NONE;
361
* this function might be called with cp->slen >= 46
362
* (i.e. when called with hostname to check if it's an IP addr).
364
if (src->slen >= PJ_INET6_ADDRSTRLEN) {
365
return PJ_ENAMETOOLONG;
368
pj_memcpy(tempaddr, src->ptr, src->slen);
369
tempaddr[src->slen] = '\0';
372
wchar_t tempaddr16[PJ_INET6_ADDRSTRLEN];
373
pj_ansi_to_unicode(tempaddr, pj_ansi_strlen(tempaddr),
374
tempaddr16, sizeof(tempaddr16));
376
TBuf<PJ_INET6_ADDRSTRLEN> ip_addr((const TText*)tempaddr16);
380
if (addr.Input(ip_addr) == KErrNone) {
381
if (af==PJ_AF_INET) {
382
/* Success (Symbian IP address is in host byte order) */
383
pj_uint32_t ip = pj_htonl(addr.Address());
384
pj_memcpy(dst, &ip, 4);
385
} else if (af==PJ_AF_INET6) {
386
const TIp6Addr & ip6 = addr.Ip6Address();
387
pj_memcpy(dst, ip6.u.iAddr8, 16);
389
pj_assert(!"Unexpected!");
400
* Convert IPv4/IPv6 address to text.
402
PJ_DEF(pj_status_t) pj_inet_ntop(int af, const void *src,
406
PJ_ASSERT_RETURN(src && dst && size, PJ_EINVAL);
410
if (af==PJ_AF_INET) {
412
TBuf<PJ_INET_ADDRSTRLEN> str16;
415
if (size < PJ_INET_ADDRSTRLEN)
418
pj_memcpy(&inaddr, src, 4);
420
/* Symbian IP address is in host byte order */
421
TInetAddr temp_addr((TUint32)pj_ntohl(inaddr.s_addr), (TUint)0);
422
temp_addr.Output(str16);
424
pj_unicode_to_ansi((const wchar_t*)str16.PtrZ(), str16.Length(),
428
} else if (af==PJ_AF_INET6) {
429
TBuf<PJ_INET6_ADDRSTRLEN> str16;
431
if (size < PJ_INET6_ADDRSTRLEN)
435
pj_memcpy(ip6.u.iAddr8, src, 16);
437
TInetAddr temp_addr(ip6, (TUint)0);
438
temp_addr.Output(str16);
440
pj_unicode_to_ansi((const wchar_t*)str16.PtrZ(), str16.Length(),
445
pj_assert(!"Unsupport address family");
454
PJ_DEF(const pj_str_t*) pj_gethostname(void)
456
static char buf[PJ_MAX_HOSTNAME];
457
static pj_str_t hostname;
461
if (hostname.ptr == NULL) {
462
RHostResolver &resv = PjSymbianOS::Instance()->GetResolver(PJ_AF_INET);
463
TRequestStatus reqStatus;
466
// Return empty hostname if access point is marked as down by app.
467
PJ_SYMBIAN_CHECK_CONNECTION2(&hostname);
469
resv.GetHostName(tmpName, reqStatus);
470
User::WaitForRequest(reqStatus);
472
hostname.ptr = pj_unicode_to_ansi((const wchar_t*)tmpName.Ptr(), tmpName.Length(),
474
hostname.slen = tmpName.Length();
480
* Create new socket/endpoint for communication and returns a descriptor.
482
PJ_DEF(pj_status_t) pj_sock_socket(int af,
492
PJ_ASSERT_RETURN(p_sock!=NULL, PJ_EINVAL);
494
// Return failure if access point is marked as down by app.
495
PJ_SYMBIAN_CHECK_CONNECTION();
497
/* Set proto if none is specified. */
499
if (type == pj_SOCK_STREAM())
500
proto = KProtocolInetTcp;
501
else if (type == pj_SOCK_DGRAM())
502
proto = KProtocolInetUdp;
505
/* Create Symbian RSocket */
507
if (PjSymbianOS::Instance()->Connection())
508
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
510
*PjSymbianOS::Instance()->Connection());
512
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
516
return PJ_RETURN_OS_ERROR(rc);
519
/* Wrap Symbian RSocket into PJLIB's CPjSocket, and return to caller */
520
CPjSocket *pjSock = new CPjSocket(af, type, rSock);
521
*p_sock = (pj_sock_t)pjSock;
530
PJ_DEF(pj_status_t) pj_sock_bind( pj_sock_t sock,
531
const pj_sockaddr_t *addr,
539
PJ_ASSERT_RETURN(sock != 0, PJ_EINVAL);
540
PJ_ASSERT_RETURN(addr && len>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL);
542
// Convert PJLIB's pj_sockaddr into Symbian's TInetAddr
544
status = PjSymbianOS::pj2Addr(*(pj_sockaddr*)addr, len, inetAddr);
545
if (status != PJ_SUCCESS)
548
// Get the RSocket instance
549
RSocket &rSock = ((CPjSocket*)sock)->Socket();
552
rc = rSock.Bind(inetAddr);
554
return (rc==KErrNone) ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc);
561
PJ_DEF(pj_status_t) pj_sock_bind_in( pj_sock_t sock,
569
pj_bzero(&addr, sizeof(addr));
570
addr.sin_family = PJ_AF_INET;
571
addr.sin_addr.s_addr = pj_htonl(addr32);
572
addr.sin_port = pj_htons(port);
574
return pj_sock_bind(sock, &addr, sizeof(pj_sockaddr_in));
581
PJ_DEF(pj_status_t) pj_sock_close(pj_sock_t sock)
585
PJ_ASSERT_RETURN(sock != 0, PJ_EINVAL);
587
CPjSocket *pjSock = (CPjSocket*)sock;
589
// This will close the socket.
598
PJ_DEF(pj_status_t) pj_sock_getpeername( pj_sock_t sock,
604
PJ_ASSERT_RETURN(sock && addr && namelen &&
605
*namelen>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL);
607
CPjSocket *pjSock = (CPjSocket*)sock;
608
RSocket &rSock = pjSock->Socket();
610
// Socket must be connected.
611
PJ_ASSERT_RETURN(pjSock->IsConnected(), PJ_EINVALIDOP);
614
rSock.RemoteName(inetAddr);
616
return PjSymbianOS::Addr2pj(inetAddr, *(pj_sockaddr*)addr, namelen);
622
PJ_DEF(pj_status_t) pj_sock_getsockname( pj_sock_t sock,
628
PJ_ASSERT_RETURN(sock && addr && namelen &&
629
*namelen>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL);
631
CPjSocket *pjSock = (CPjSocket*)sock;
632
RSocket &rSock = pjSock->Socket();
635
rSock.LocalName(inetAddr);
637
return PjSymbianOS::Addr2pj(inetAddr, *(pj_sockaddr*)addr, namelen);
643
PJ_DEF(pj_status_t) pj_sock_send(pj_sock_t sock,
649
PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL);
651
// Return failure if access point is marked as down by app.
652
PJ_SYMBIAN_CHECK_CONNECTION();
654
CPjSocket *pjSock = (CPjSocket*)sock;
655
RSocket &rSock = pjSock->Socket();
657
// send() should only be called to connected socket
658
PJ_ASSERT_RETURN(pjSock->IsConnected(), PJ_EINVALIDOP);
660
TPtrC8 data((const TUint8*)buf, (TInt)*len);
661
TRequestStatus reqStatus;
662
TSockXfrLength sentLen;
664
rSock.Send(data, flags, reqStatus, sentLen);
665
User::WaitForRequest(reqStatus);
667
if (reqStatus.Int()==KErrNone) {
668
//*len = (TInt) sentLen.Length();
671
return PJ_RETURN_OS_ERROR(reqStatus.Int());
678
PJ_DEF(pj_status_t) pj_sock_sendto(pj_sock_t sock,
682
const pj_sockaddr_t *to,
688
PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL);
690
// Return failure if access point is marked as down by app.
691
PJ_SYMBIAN_CHECK_CONNECTION();
693
CPjSocket *pjSock = (CPjSocket*)sock;
694
RSocket &rSock = pjSock->Socket();
696
// Only supports AF_INET for now
697
PJ_ASSERT_RETURN(tolen>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL);
700
status = PjSymbianOS::pj2Addr(*(pj_sockaddr*)to, tolen, inetAddr);
701
if (status != PJ_SUCCESS)
704
TPtrC8 data((const TUint8*)buf, (TInt)*len);
705
TRequestStatus reqStatus;
706
TSockXfrLength sentLen;
708
rSock.SendTo(data, inetAddr, flags, reqStatus, sentLen);
709
User::WaitForRequest(reqStatus);
711
if (reqStatus.Int()==KErrNone) {
712
//For some reason TSockXfrLength is not returning correctly!
713
//*len = (TInt) sentLen.Length();
716
return PJ_RETURN_OS_ERROR(reqStatus.Int());
722
PJ_DEF(pj_status_t) pj_sock_recv(pj_sock_t sock,
729
PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL);
730
PJ_ASSERT_RETURN(*len > 0, PJ_EINVAL);
732
// Return failure if access point is marked as down by app.
733
PJ_SYMBIAN_CHECK_CONNECTION();
735
CPjSocket *pjSock = (CPjSocket*)sock;
737
if (pjSock->Reader()) {
738
CPjSocketReader *reader = pjSock->Reader();
740
while (reader->IsActive() && !reader->HasData()) {
741
User::WaitForAnyRequest();
744
if (reader->HasData()) {
745
TPtr8 data((TUint8*)buf, (TInt)*len);
748
reader->ReadData(data, &inetAddr);
750
*len = data.Length();
755
TRequestStatus reqStatus;
756
TSockXfrLength recvLen;
757
TPtr8 data((TUint8*)buf, (TInt)*len, (TInt)*len);
759
if (pjSock->IsDatagram()) {
760
pjSock->Socket().Recv(data, flags, reqStatus);
762
// Using static like this is not pretty, but we don't need to use
763
// the value anyway, hence doing it like this is probably most
765
static TSockXfrLength len;
766
pjSock->Socket().RecvOneOrMore(data, flags, reqStatus, len);
768
User::WaitForRequest(reqStatus);
770
if (reqStatus == KErrNone) {
771
//*len = (TInt)recvLen.Length();
772
*len = data.Length();
776
return PJ_RETURN_OS_ERROR(reqStatus.Int());
783
PJ_DEF(pj_status_t) pj_sock_recvfrom(pj_sock_t sock,
792
PJ_ASSERT_RETURN(sock && buf && len && from && fromlen, PJ_EINVAL);
793
PJ_ASSERT_RETURN(*len > 0, PJ_EINVAL);
794
PJ_ASSERT_RETURN(*fromlen >= (int)sizeof(pj_sockaddr_in), PJ_EINVAL);
796
// Return failure if access point is marked as down by app.
797
PJ_SYMBIAN_CHECK_CONNECTION();
799
CPjSocket *pjSock = (CPjSocket*)sock;
800
RSocket &rSock = pjSock->Socket();
802
if (pjSock->Reader()) {
803
CPjSocketReader *reader = pjSock->Reader();
805
while (reader->IsActive() && !reader->HasData()) {
806
User::WaitForAnyRequest();
809
if (reader->HasData()) {
810
TPtr8 data((TUint8*)buf, (TInt)*len);
813
reader->ReadData(data, &inetAddr);
815
*len = data.Length();
817
if (from && fromlen) {
818
return PjSymbianOS::Addr2pj(inetAddr, *(pj_sockaddr*)from,
827
TRequestStatus reqStatus;
828
TSockXfrLength recvLen;
829
TPtr8 data((TUint8*)buf, (TInt)*len, (TInt)*len);
831
rSock.RecvFrom(data, inetAddr, flags, reqStatus, recvLen);
832
User::WaitForRequest(reqStatus);
834
if (reqStatus == KErrNone) {
835
//*len = (TInt)recvLen.Length();
836
*len = data.Length();
837
return PjSymbianOS::Addr2pj(inetAddr, *(pj_sockaddr*)from, fromlen);
841
return PJ_RETURN_OS_ERROR(reqStatus.Int());
848
PJ_DEF(pj_status_t) pj_sock_getsockopt( pj_sock_t sock,
854
// Not supported for now.
856
PJ_UNUSED_ARG(level);
857
PJ_UNUSED_ARG(optname);
858
PJ_UNUSED_ARG(optval);
859
PJ_UNUSED_ARG(optlen);
860
return PJ_EINVALIDOP;
866
PJ_DEF(pj_status_t) pj_sock_setsockopt( pj_sock_t sock,
872
// Not supported for now.
874
PJ_UNUSED_ARG(level);
875
PJ_UNUSED_ARG(optname);
876
PJ_UNUSED_ARG(optval);
877
PJ_UNUSED_ARG(optlen);
878
return PJ_EINVALIDOP;
884
PJ_DEF(pj_status_t) pj_sock_connect( pj_sock_t sock,
885
const pj_sockaddr_t *addr,
892
PJ_ASSERT_RETURN(sock && addr && namelen, PJ_EINVAL);
893
PJ_ASSERT_RETURN(((pj_sockaddr*)addr)->addr.sa_family == PJ_AF_INET,
896
// Return failure if access point is marked as down by app.
897
PJ_SYMBIAN_CHECK_CONNECTION();
899
CPjSocket *pjSock = (CPjSocket*)sock;
900
RSocket &rSock = pjSock->Socket();
903
TRequestStatus reqStatus;
905
status = PjSymbianOS::pj2Addr(*(pj_sockaddr*)addr, namelen, inetAddr);
906
if (status != PJ_SUCCESS)
909
rSock.Connect(inetAddr, reqStatus);
910
User::WaitForRequest(reqStatus);
912
if (reqStatus == KErrNone) {
913
pjSock->SetConnected(true);
916
return PJ_RETURN_OS_ERROR(reqStatus.Int());
925
PJ_DEF(pj_status_t) pj_sock_shutdown( pj_sock_t sock,
930
PJ_ASSERT_RETURN(sock, PJ_EINVAL);
932
CPjSocket *pjSock = (CPjSocket*)sock;
933
RSocket &rSock = pjSock->Socket();
935
RSocket::TShutdown aHow;
936
if (how == PJ_SD_RECEIVE)
937
aHow = RSocket::EStopInput;
938
else if (how == PJ_SHUT_WR)
939
aHow = RSocket::EStopOutput;
941
aHow = RSocket::ENormal;
943
TRequestStatus reqStatus;
945
rSock.Shutdown(aHow, reqStatus);
946
User::WaitForRequest(reqStatus);
948
if (reqStatus == KErrNone) {
951
return PJ_RETURN_OS_ERROR(reqStatus.Int());
956
* Start listening to incoming connections.
958
PJ_DEF(pj_status_t) pj_sock_listen( pj_sock_t sock,
963
PJ_ASSERT_RETURN(sock && backlog, PJ_EINVAL);
965
CPjSocket *pjSock = (CPjSocket*)sock;
966
RSocket &rSock = pjSock->Socket();
968
TInt rc = rSock.Listen((TUint)backlog);
970
if (rc == KErrNone) {
973
return PJ_RETURN_OS_ERROR(rc);
978
* Accept incoming connections
980
PJ_DEF(pj_status_t) pj_sock_accept( pj_sock_t serverfd,
987
PJ_ASSERT_RETURN(serverfd && newsock, PJ_EINVAL);
989
CPjSocket *pjSock = (CPjSocket*)serverfd;
990
RSocket &rSock = pjSock->Socket();
992
// Create a 'blank' socket
994
newSock.Open(PjSymbianOS::Instance()->SocketServ());
997
TRequestStatus reqStatus;
999
rSock.Accept(newSock, reqStatus);
1000
User::WaitForRequest(reqStatus);
1002
if (reqStatus != KErrNone) {
1003
return PJ_RETURN_OS_ERROR(reqStatus.Int());
1007
CPjSocket *newPjSock = new CPjSocket(pjSock->GetAf(), pjSock->GetSockType(),
1009
newPjSock->SetConnected(true);
1011
*newsock = (pj_sock_t) newPjSock;
1013
if (addr && addrlen) {
1014
return pj_sock_getpeername(*newsock, addr, addrlen);
1019
#endif /* PJ_HAS_TCP */