24
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// This file contains the implementation of the RSmsSocket class
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "smsustrm.h"
|
|
23 |
#include "smsumain.h"
|
|
24 |
#include <es_sock.h>
|
|
25 |
#include "smsstacklog.h"
|
|
26 |
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Constructor
|
|
30 |
* @param aSocket representing the socket the buffer reads and writes to.
|
|
31 |
*/
|
|
32 |
RSmsSocketBuf::RSmsSocketBuf(RSocket& aSocket)
|
|
33 |
:iSocket(aSocket)
|
|
34 |
{
|
|
35 |
SetBuf(ERead|EWrite,iBuffer,iBuffer);
|
|
36 |
} // RSmsSocketBuf::RSmsSocketBuf
|
|
37 |
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Fills the buffer's read area from the socket.
|
|
41 |
*
|
|
42 |
* @leave The function panics if the socket is not readable.
|
|
43 |
* @param aMaxLength Unused
|
|
44 |
* @return The length of the buffer
|
|
45 |
*/
|
|
46 |
TInt RSmsSocketBuf::UnderflowL(TInt)
|
|
47 |
//Leaves if the Request Status (s) is in error
|
|
48 |
//Panics if ERead==0
|
|
49 |
//
|
|
50 |
{
|
|
51 |
LOGSMSU1("RSmsSocketBuf::UnderflowL()");
|
|
52 |
|
|
53 |
__ASSERT_ALWAYS(Avail(ERead)==0,SmsuPanic(KSsmuPanicStreamReadUnavailable));
|
|
54 |
SocketWriteL();
|
|
55 |
SetBuf(EWrite,iBuffer,iBuffer);
|
|
56 |
//
|
|
57 |
TRequestStatus s;
|
|
58 |
TSockXfrLength l;
|
|
59 |
TPtr8 ptr(iBuffer,sizeof(iBuffer));
|
|
60 |
// iSocket.RecvOneOrMore(ptr,0,s,l);
|
|
61 |
iSocket.Recv(ptr,0,s,l);
|
|
62 |
User::WaitForRequest(s);
|
|
63 |
User::LeaveIfError(s.Int());
|
|
64 |
TInt len=ptr.Length();
|
|
65 |
SetBuf(ERead,iBuffer,iBuffer+len);
|
|
66 |
return len;
|
|
67 |
} // RSmsSocketBuf::UnderflowL
|
|
68 |
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Empties the buffer and sets up the buffer's write area.
|
|
72 |
*
|
|
73 |
* The function panics if the socket is not writable.
|
|
74 |
*/
|
|
75 |
void RSmsSocketBuf::OverflowL()
|
|
76 |
//Panics if EWrite == 0
|
|
77 |
{
|
|
78 |
LOGSMSU1("RSmsSocketBuf::OverflowL()");
|
|
79 |
|
|
80 |
__ASSERT_ALWAYS(Avail(EWrite)==0,SmsuPanic(KSsmuPanicStreamWriteUnavailable));
|
|
81 |
SetBuf(ERead,iBuffer,iBuffer);
|
|
82 |
//
|
|
83 |
SocketWriteL();
|
|
84 |
SetBuf(EWrite,iBuffer,iBuffer+sizeof(iBuffer));
|
|
85 |
} // RSmsSocketBuf::OverflowL
|
|
86 |
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Synchronises the stream buffer with the stream, leaving if any error occurs.
|
|
90 |
*/
|
|
91 |
void RSmsSocketBuf::DoSynchL()
|
|
92 |
{
|
|
93 |
LOGSMSU1("RSmsSocketBuf::DoSynchL()");
|
|
94 |
|
|
95 |
SocketWriteL();
|
|
96 |
SetBuf(ERead|EWrite,iBuffer,iBuffer);
|
|
97 |
} // RSmsSocketBuf::DoSynchL
|
|
98 |
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Writes the buffered data to the socket.
|
|
102 |
*/
|
|
103 |
void RSmsSocketBuf::SocketWriteL()
|
|
104 |
{
|
|
105 |
LOGSMSU1("RSmsSocketBuf::SocketWriteL()");
|
|
106 |
|
|
107 |
TInt length=Lag(EWrite);
|
|
108 |
if (length==0)
|
|
109 |
return;
|
|
110 |
//
|
|
111 |
TRequestStatus s;
|
|
112 |
iSocket.Write(TPtrC8(iBuffer,length),s);
|
|
113 |
User::WaitForRequest(s);
|
|
114 |
User::LeaveIfError(s.Int());
|
|
115 |
} // RSmsSocketBuf::SocketWriteL
|
|
116 |
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Constructor.
|
|
120 |
*
|
|
121 |
* @param aSocket RSmsSocketBuf through which to read data
|
|
122 |
* @capability None
|
|
123 |
*/
|
|
124 |
EXPORT_C RSmsSocketReadStream::RSmsSocketReadStream(RSocket& aSocket)
|
|
125 |
:RReadStream(&iBuf),
|
|
126 |
iBuf(aSocket)
|
|
127 |
{
|
|
128 |
LOGSMSU1("RSmsSocketReadStream::RSmsSocketReadStream()");
|
|
129 |
|
|
130 |
} // RSmsSocketReadStream::RSmsSocketReadStream
|
|
131 |
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Constructor.
|
|
135 |
*
|
|
136 |
* @param aSocket RSmsSocketBuf through which to write data
|
|
137 |
* @capability None
|
|
138 |
*/
|
|
139 |
EXPORT_C RSmsSocketWriteStream::RSmsSocketWriteStream(RSocket& aSocket)
|
|
140 |
:RWriteStream(&iBuf),
|
|
141 |
iBuf(aSocket)
|
|
142 |
{
|
|
143 |
LOGSMSU1("RSmsSocketWriteStream::RSmsSocketWriteStream()");
|
|
144 |
|
|
145 |
} // RSmsSocketWriteStream::RSmsSocketWriteStream
|
|
146 |
|