1
/* $Id: sock_select_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
20
#include <pj/sock_select.h>
22
#include <pj/assert.h>
24
#include "os_symbian.h"
30
CPjSocket *sock[PJ_IOQUEUE_MAX_HANDLES];
34
PJ_DEF(void) PJ_FD_ZERO(pj_fd_set_t *fdsetp)
36
symbian_fd_set *fds = (symbian_fd_set *)fdsetp;
41
PJ_DEF(void) PJ_FD_SET(pj_sock_t fd, pj_fd_set_t *fdsetp)
43
symbian_fd_set *fds = (symbian_fd_set *)fdsetp;
45
PJ_ASSERT_ON_FAIL(fds->count < PJ_IOQUEUE_MAX_HANDLES, return);
46
fds->sock[fds->count++] = (CPjSocket*)fd;
50
PJ_DEF(void) PJ_FD_CLR(pj_sock_t fd, pj_fd_set_t *fdsetp)
52
symbian_fd_set *fds = (symbian_fd_set *)fdsetp;
55
for (i=0; i<fds->count; ++i) {
56
if (fds->sock[i] == (CPjSocket*)fd) {
57
pj_array_erase(fds->sock, sizeof(fds->sock[0]), fds->count, i);
65
PJ_DEF(pj_bool_t) PJ_FD_ISSET(pj_sock_t fd, const pj_fd_set_t *fdsetp)
67
symbian_fd_set *fds = (symbian_fd_set *)fdsetp;
70
for (i=0; i<fds->count; ++i) {
71
if (fds->sock[i] == (CPjSocket*)fd) {
79
PJ_DEF(pj_size_t) PJ_FD_COUNT(const pj_fd_set_t *fdsetp)
81
symbian_fd_set *fds = (symbian_fd_set *)fdsetp;
86
PJ_DEF(int) pj_sock_select( int n,
88
pj_fd_set_t *writefds,
89
pj_fd_set_t *exceptfds,
90
const pj_time_val *timeout)
92
CPjTimeoutTimer *pjTimer;
96
PJ_UNUSED_ARG(writefds);
97
PJ_UNUSED_ARG(exceptfds);
100
pjTimer = PjSymbianOS::Instance()->SelectTimeoutTimer();
101
pjTimer->StartTimer(timeout->sec*1000 + timeout->msec);
107
/* Scan for readable sockets */
110
symbian_fd_set *fds = (symbian_fd_set *)readfds;
113
/* Scan sockets for readily available data */
114
for (i=0; i<fds->count; ++i) {
115
CPjSocket *pjsock = fds->sock[i];
117
if (pjsock->Reader()) {
118
if (pjsock->Reader()->HasData() && !pjsock->Reader()->IsActive()) {
120
/* Found socket with data ready */
122
PJ_FD_SET((pj_sock_t)pjsock, readfds);
124
/* Cancel timer, if any */
129
/* Clear writable and exception fd_set */
131
PJ_FD_ZERO(writefds);
133
PJ_FD_ZERO(exceptfds);
137
} else if (!pjsock->Reader()->IsActive())
138
pjsock->Reader()->StartRecvFrom();
141
pjsock->CreateReader();
142
pjsock->Reader()->StartRecvFrom();
146
PjSymbianOS::Instance()->WaitForActiveObjects();
148
} while (pjTimer==NULL || !pjTimer->HasTimedOut());
157
PJ_FD_ZERO(writefds);
159
PJ_FD_ZERO(exceptfds);