Пример #1
0
/*
 * Receive data.
 */
PJ_DEF(pj_status_t) pj_sock_recv(pj_sock_t sock,
				 void *buf,
				 pj_ssize_t *len,
				 unsigned flags)
{
    PJ_CHECK_STACK();

    PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL);
    PJ_ASSERT_RETURN(*len > 0, PJ_EINVAL);

    // Return failure if access point is marked as down by app.
    PJ_SYMBIAN_CHECK_CONNECTION();

    CPjSocket *pjSock = (CPjSocket*)sock;

    if (pjSock->Reader()) {
	CPjSocketReader *reader = pjSock->Reader();

	while (reader->IsActive() && !reader->HasData()) {
	    User::WaitForAnyRequest();
	}

	if (reader->HasData()) {
	    TPtr8 data((TUint8*)buf, (TInt)*len);
	    TInetAddr inetAddr;

	    reader->ReadData(data, &inetAddr);

	    *len = data.Length();
	    return PJ_SUCCESS;
	}
    }

    TRequestStatus reqStatus;
    TSockXfrLength recvLen;
    TPtr8 data((TUint8*)buf, (TInt)*len, (TInt)*len);

    if (pjSock->IsDatagram()) {
	pjSock->Socket().Recv(data, flags, reqStatus);
    } else {
	// Using static like this is not pretty, but we don't need to use
	// the value anyway, hence doing it like this is probably most
	// optimal.
	static TSockXfrLength len;
	pjSock->Socket().RecvOneOrMore(data, flags, reqStatus, len);
    }
    User::WaitForRequest(reqStatus);

    if (reqStatus == KErrNone) {
	//*len = (TInt)recvLen.Length();
	*len = data.Length();
	return PJ_SUCCESS;
    } else {
	*len = -1;
	return PJ_RETURN_OS_ERROR(reqStatus.Int());
    }
}
Пример #2
0
//
// Start asynchronous recv() operation
//
pj_status_t CIoqueueCallback::StartRead (pj_ioqueue_op_key_t *op_key,
        void *buf, pj_ssize_t *size,
        unsigned flags,
        pj_sockaddr_t *addr, int *addrlen)
{
    PJ_ASSERT_RETURN (IsActive() ==false, PJ_EBUSY);
    PJ_ASSERT_RETURN (pending_data_.common_.op_key_==NULL, PJ_EBUSY);

    flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC;

    pending_data_.read_.op_key_ = op_key;
    pending_data_.read_.addr_ = addr;
    pending_data_.read_.addrlen_ = addrlen;

    aBufferPtr_.Set ( (TUint8*) buf, 0, (TInt) *size);

    type_ = TYPE_READ;

    if (addr && addrlen) {
        sock_->Socket().RecvFrom (aBufferPtr_, aAddress_, flags, iStatus);
    } else {
        aAddress_.SetAddress (0);
        aAddress_.SetPort (0);

        if (sock_->IsDatagram()) {
            sock_->Socket().Recv (aBufferPtr_, flags, iStatus);
        } else {
            // Using static like this is not pretty, but we don't need to use
            // the value anyway, hence doing it like this is probably most
            // optimal.
            static TSockXfrLength len;
            sock_->Socket().RecvOneOrMore (aBufferPtr_, flags, iStatus, len);
        }
    }

    SetActive();
    return PJ_EPENDING;
}