|
1 // Copyright (c) 2002-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains ESock Test cases from section 1 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <ss_std.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "SocketTestSection31.h" |
|
24 #include <test/es_dummy.h> |
|
25 |
|
26 const TInt KBufferLength= 60000; |
|
27 |
|
28 |
|
29 |
|
30 // Test step 31.1 |
|
31 // Sending more than 16k packets. |
|
32 // Stream |
|
33 // Blocking mode |
|
34 // Using pdummy |
|
35 // |
|
36 const TDesC& CSocketTest31_1::GetTestName() |
|
37 { |
|
38 _LIT(ret,"Test31.1"); |
|
39 return ret; |
|
40 } |
|
41 |
|
42 enum TVerdict CSocketTest31_1::InternalDoTestStepL( void ) |
|
43 { |
|
44 TVerdict verdict = EPass; |
|
45 |
|
46 Logger().WriteFormat(_L("Test Purpose: Sending large amount of data (more than 16K,60k) by using Stream")); |
|
47 |
|
48 // connect to esock |
|
49 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
50 RSocketServ ss; |
|
51 |
|
52 TSessionPref pref; |
|
53 pref.iAddrFamily = KDummyAddrFamily; |
|
54 pref.iProtocol = KDummyFour; |
|
55 TInt ret = ss.Connect(pref); |
|
56 CleanupClosePushL(ss); |
|
57 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
58 TESTL(KErrNone == ret); |
|
59 |
|
60 Logger().WriteFormat(_L("Finding for dummy protocol 4")); |
|
61 TProtocolDesc protoInfo; |
|
62 ret = ss.FindProtocol(_L("Dummy Protocol 4"), protoInfo); |
|
63 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
64 TESTL(KErrNone == ret); |
|
65 |
|
66 Logger().WriteFormat(_L("Open a socket on Dummy Protocol 4")); |
|
67 RSocket sock; |
|
68 CleanupClosePushL (sock); |
|
69 ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
70 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
71 TESTL(KErrNone == ret); |
|
72 |
|
73 Logger().WriteFormat(_L("Perform connect")); |
|
74 TRequestStatus status; |
|
75 TSockAddr addr; |
|
76 sock.Connect(addr, status); |
|
77 User::WaitForRequest(status); |
|
78 TESTL(KErrNone == status.Int()); |
|
79 |
|
80 |
|
81 // Setting options |
|
82 // Force the Send to 'flow off' |
|
83 TBool flowOff = ETrue; |
|
84 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
85 Logger().WriteFormat(_L("SetOpt (flow off) returned %S"), &EpocErrorToText(ret)); |
|
86 TESTL(KErrNone == ret); |
|
87 |
|
88 // Setting up buffer |
|
89 HBufC8* writebuf = HBufC8::NewMaxLC(KBufferLength); |
|
90 HBufC8* readbuf = HBufC8::NewMaxLC(KBufferLength); |
|
91 |
|
92 TPtr8 ptrwritebuf(const_cast<TUint8*>(writebuf->Ptr()), KBufferLength); |
|
93 TPtr8 ptrreadbuf(const_cast<TUint8*>(readbuf->Ptr()), KBufferLength); |
|
94 |
|
95 ptrwritebuf.SetLength(ptrwritebuf.MaxLength()); |
|
96 ptrreadbuf.SetLength(ptrreadbuf.MaxLength()); |
|
97 |
|
98 // Filling buffer |
|
99 ptrwritebuf.Repeat(_L8("Stream-packet: helloworld")); |
|
100 |
|
101 TRequestStatus txStat; |
|
102 TRequestStatus rxStat; |
|
103 TSockXfrLength txlen; |
|
104 TSockXfrLength rxlen; |
|
105 TInt txSize = 0, txCnt = 0;; |
|
106 TInt rxSize = 0, rxCnt = -1; |
|
107 TBool txSentAll = EFalse; |
|
108 TBool rxRecvAll = EFalse; |
|
109 |
|
110 while(rxSize < KBufferLength) |
|
111 { |
|
112 // sending packets |
|
113 if(txStat.Int() != KRequestPending && !txSentAll) |
|
114 { |
|
115 RDebug::Printf("tx status:%d, ", txStat.Int()); |
|
116 TPtrC8 ptrtempbuf(ptrwritebuf.Mid(txSize)); |
|
117 sock.Send(ptrtempbuf, 0, txStat, txlen); |
|
118 |
|
119 // Now enable the write to complete, by ending the 'flow off' |
|
120 flowOff = EFalse; |
|
121 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
122 TESTL(KErrNone == ret); |
|
123 |
|
124 User::WaitForRequest(txStat); |
|
125 ++txCnt; |
|
126 txSize += txlen(); |
|
127 |
|
128 if(txStat!=KErrNone) |
|
129 { |
|
130 Logger().WriteFormat(_L("Error in sending packet : %d "), txStat.Int()); |
|
131 break; |
|
132 } |
|
133 RDebug::Printf("tx #%d, +%d\n", txCnt, txlen()); |
|
134 if(txSize >= KBufferLength) |
|
135 { |
|
136 txSentAll=ETrue; |
|
137 } |
|
138 } |
|
139 |
|
140 // receiving packets |
|
141 if((rxStat.Int() != KRequestPending) && !rxRecvAll) |
|
142 { |
|
143 RDebug::Printf("rx status:%d, ", rxStat.Int()); |
|
144 ++rxCnt; |
|
145 |
|
146 sock.RecvOneOrMore(ptrreadbuf, 0, rxStat, rxlen); |
|
147 User::WaitForRequest(rxStat); |
|
148 rxSize += rxlen(); |
|
149 |
|
150 if(rxStat!=KErrNone) |
|
151 { |
|
152 Logger().WriteFormat(_L("Error in receiving packet : %d "), rxStat.Int()); |
|
153 break; |
|
154 } |
|
155 RDebug::Printf("rx #%d, +%d\n", rxCnt, rxlen()); |
|
156 |
|
157 if(rxSize >= KBufferLength) |
|
158 { |
|
159 rxRecvAll=ETrue; |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy(2, writebuf); // writebuf and readbuf |
|
165 CleanupStack::PopAndDestroy(2); // sock, ss |
|
166 |
|
167 SetTestStepResult(EPass); |
|
168 return TestStepResult(); |
|
169 } |
|
170 |
|
171 // Test step 31.2 |
|
172 // Sending more than 16k packets. |
|
173 // Stream |
|
174 // Non-Blocking mode |
|
175 // Using pdummy |
|
176 // |
|
177 const TDesC& CSocketTest31_2::GetTestName() |
|
178 { |
|
179 _LIT(ret,"Test31.2"); |
|
180 return ret; |
|
181 } |
|
182 |
|
183 enum TVerdict CSocketTest31_2::InternalDoTestStepL( void ) |
|
184 { |
|
185 TVerdict verdict = EPass; |
|
186 |
|
187 Logger().WriteFormat(_L("Test Purpose: Sending large amount of data (more than 16K,60k) by using Stream")); |
|
188 |
|
189 // connect to esock |
|
190 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
191 RSocketServ ss; |
|
192 |
|
193 TSessionPref pref; |
|
194 pref.iAddrFamily = KDummyAddrFamily; |
|
195 pref.iProtocol = KDummyFour; |
|
196 TInt ret = ss.Connect(pref); |
|
197 CleanupClosePushL(ss); |
|
198 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
199 TESTL(KErrNone == ret); |
|
200 |
|
201 Logger().WriteFormat(_L("Finding for dummy protocol 4")); |
|
202 TProtocolDesc protoInfo; |
|
203 ret = ss.FindProtocol(_L("Dummy Protocol 4"), protoInfo); |
|
204 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
205 TESTL(KErrNone == ret); |
|
206 |
|
207 Logger().WriteFormat(_L("Open a socket on Dummy Protocol 4")); |
|
208 RSocket sock; |
|
209 CleanupClosePushL (sock); |
|
210 ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
211 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
212 TESTL(KErrNone == ret); |
|
213 |
|
214 Logger().WriteFormat(_L("Perform connect")); |
|
215 TRequestStatus status; |
|
216 TSockAddr addr; |
|
217 sock.Connect(addr, status); |
|
218 User::WaitForRequest(status); |
|
219 TESTL(KErrNone == status.Int()); |
|
220 |
|
221 |
|
222 // Setting options |
|
223 // Force the Send to 'flow off' |
|
224 TBool flowOff = ETrue; |
|
225 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
226 Logger().WriteFormat(_L("SetOpt (flow off) returned %S"), &EpocErrorToText(ret)); |
|
227 TESTL(KErrNone == ret); |
|
228 |
|
229 ret = sock.SetOpt(KSONonBlockingIO, KSOLSocket, 1); |
|
230 Logger().WriteFormat(_L("SetOpt NonBlockingIO returned %S"), &EpocErrorToText(ret)); |
|
231 TESTL(KErrNone == ret); |
|
232 |
|
233 // Setting up buffer |
|
234 HBufC8* writebuf = HBufC8::NewMaxLC(KBufferLength); |
|
235 HBufC8* readbuf = HBufC8::NewMaxLC(KBufferLength); |
|
236 |
|
237 TPtr8 ptrwritebuf(const_cast<TUint8*>(writebuf->Ptr()), KBufferLength); |
|
238 TPtr8 ptrreadbuf(const_cast<TUint8*>(readbuf->Ptr()), KBufferLength); |
|
239 |
|
240 ptrwritebuf.SetLength(ptrwritebuf.MaxLength()); |
|
241 ptrreadbuf.SetLength(ptrreadbuf.MaxLength()); |
|
242 |
|
243 // Filling buffer |
|
244 ptrwritebuf.Repeat(_L8("Stream-packet: helloworld")); |
|
245 |
|
246 TRequestStatus txStat; |
|
247 TRequestStatus rxStat; |
|
248 TSockXfrLength txlen; |
|
249 TSockXfrLength rxlen; |
|
250 TInt txSize = 0, txCnt = 0;; |
|
251 TInt rxSize = 0, rxCnt = -1; |
|
252 TBool txSentAll = EFalse; |
|
253 TBool rxRecvAll = EFalse; |
|
254 |
|
255 while(rxSize < KBufferLength) |
|
256 { |
|
257 // sending packets |
|
258 if(txStat.Int() != KRequestPending && !txSentAll) |
|
259 { |
|
260 RDebug::Printf("tx status:%d, ", txStat.Int()); |
|
261 TPtrC8 ptrtempbuf(ptrwritebuf.Mid(txSize)); |
|
262 sock.Send(ptrtempbuf, 0, txStat, txlen); |
|
263 |
|
264 // Now enable the write to complete, by ending the 'flow off' |
|
265 flowOff = EFalse; |
|
266 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
267 TESTL(KErrNone == ret); |
|
268 |
|
269 User::WaitForRequest(txStat); |
|
270 ++txCnt; |
|
271 txSize += txlen(); |
|
272 |
|
273 if(txStat!=KErrNone) |
|
274 { |
|
275 Logger().WriteFormat(_L("Error in sending packet : %d "), txStat.Int()); |
|
276 break; |
|
277 } |
|
278 RDebug::Printf("tx #%d, +%d\n", txCnt, txlen()); |
|
279 if(txSize >= KBufferLength) |
|
280 { |
|
281 txSentAll=ETrue; |
|
282 } |
|
283 } |
|
284 |
|
285 // receiving packets |
|
286 if((rxStat.Int() != KRequestPending) && !rxRecvAll) |
|
287 { |
|
288 RDebug::Printf("rx status:%d, ", rxStat.Int()); |
|
289 ++rxCnt; |
|
290 |
|
291 sock.RecvOneOrMore(ptrreadbuf, 0, rxStat, rxlen); |
|
292 User::WaitForRequest(rxStat); |
|
293 rxSize += rxlen(); |
|
294 |
|
295 if(rxStat!=KErrNone && rxStat!=KErrWouldBlock) |
|
296 { |
|
297 Logger().WriteFormat(_L("Error in receiving packet : %d "), rxStat.Int()); |
|
298 break; |
|
299 } |
|
300 RDebug::Printf("rx #%d, +%d\n", rxCnt, rxlen()); |
|
301 |
|
302 if(rxSize >= KBufferLength) |
|
303 { |
|
304 rxRecvAll=ETrue; |
|
305 } |
|
306 } |
|
307 } |
|
308 |
|
309 CleanupStack::PopAndDestroy(2, writebuf); // writebuf and readbuf |
|
310 CleanupStack::PopAndDestroy(2); // sock, ss |
|
311 |
|
312 SetTestStepResult(EPass); |
|
313 return TestStepResult(); |
|
314 } |
|
315 |
|
316 // Test step 31.3 |
|
317 // Sending more than 16k packets. |
|
318 // Datagram |
|
319 // Blocking mode |
|
320 // |
|
321 const TDesC& CSocketTest31_3::GetTestName() |
|
322 { |
|
323 _LIT(ret,"Test31.3"); |
|
324 return ret; |
|
325 } |
|
326 |
|
327 enum TVerdict CSocketTest31_3::InternalDoTestStepL( void ) |
|
328 { |
|
329 TVerdict verdict = EPass; |
|
330 |
|
331 Logger().WriteFormat(_L("Test Purpose: Repeat send over 64K datagram using TSockXfrLength.")); |
|
332 |
|
333 // connect to esock |
|
334 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
335 RSocketServ ss; |
|
336 |
|
337 // protocol allowing unlimited datagram size |
|
338 TSessionPref pref; |
|
339 pref.iAddrFamily = KDummyAddrFamily; |
|
340 pref.iProtocol = KDummyFive; |
|
341 TInt ret = ss.Connect(pref); |
|
342 |
|
343 CleanupClosePushL(ss); |
|
344 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
345 TESTL(KErrNone == ret); |
|
346 |
|
347 Logger().WriteFormat(_L("Finding for dummy protocol 5")); |
|
348 TProtocolDesc protoInfo; |
|
349 ret = ss.FindProtocol(_L("Dummy Protocol 5"), protoInfo); |
|
350 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
351 TESTL(KErrNone == ret); |
|
352 |
|
353 Logger().WriteFormat(_L("Opening a socket")); |
|
354 RSocket sock; |
|
355 ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
356 CleanupClosePushL(sock); |
|
357 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
358 TESTL(KErrNone == ret); |
|
359 |
|
360 TPckgBuf<TUint> lenbuf; |
|
361 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
362 ret = sock.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
363 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
364 &EpocErrorToText(ret), lenbuf()); |
|
365 TESTL(KErrNone == ret); |
|
366 |
|
367 TUint x(KBufferLength); |
|
368 lenbuf() = x; |
|
369 Logger().WriteFormat(_L("Setting SendBuf length to %d"), lenbuf()); |
|
370 ret = sock.SetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
371 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
372 TESTL(KErrNone == ret); |
|
373 |
|
374 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
375 ret = sock.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
376 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), &EpocErrorToText(ret), lenbuf()); |
|
377 TESTL(KErrNone == ret); |
|
378 TESTL(lenbuf() == x); |
|
379 |
|
380 // Force the SendTo to 'flow off' |
|
381 TBool flowOff = ETrue; |
|
382 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
383 Logger().WriteFormat(_L("SetOpt (flow off) returned %S"), &EpocErrorToText(ret)); |
|
384 TESTL(KErrNone == ret); |
|
385 |
|
386 Logger().WriteFormat(_L("Try sending datagram over protocol allowing unlimited datagram size")); |
|
387 TInetAddr destAddr; |
|
388 TRequestStatus status; |
|
389 |
|
390 // Setting up buffer |
|
391 HBufC8* writebuf = HBufC8::NewMaxLC(KBufferLength); |
|
392 HBufC8* readbuf = HBufC8::NewMaxLC(KBufferLength); |
|
393 |
|
394 TPtr8 ptrwritebuf(const_cast<TUint8*>(writebuf->Ptr()), KBufferLength); |
|
395 TPtr8 ptrreadbuf(const_cast<TUint8*>(readbuf->Ptr()), KBufferLength); |
|
396 |
|
397 ptrwritebuf.SetLength(ptrwritebuf.MaxLength()); |
|
398 ptrreadbuf.SetLength(ptrreadbuf.MaxLength()); |
|
399 |
|
400 // Filling buffer |
|
401 ptrwritebuf.Repeat(_L8("Datagram-packet: helloworld")); |
|
402 |
|
403 TRequestStatus txStat; |
|
404 TRequestStatus rxStat; |
|
405 TSockXfrLength txlen; |
|
406 TSockXfrLength rxlen; |
|
407 TInt txSize = 0, txCnt = 0;; |
|
408 TInt rxSize = 0, rxCnt = -1; |
|
409 TBool txSentAll = EFalse; |
|
410 TBool rxRecvAll = EFalse; |
|
411 |
|
412 while(rxSize < KBufferLength) |
|
413 { |
|
414 // sending packets |
|
415 if(txStat.Int() != KRequestPending && !txSentAll) |
|
416 { |
|
417 RDebug::Printf("tx status:%d, ", txStat.Int()); |
|
418 TPtrC8 ptrtempbuf(ptrwritebuf.Mid(txSize)); |
|
419 sock.SendTo(ptrtempbuf, destAddr, 0, txStat, txlen); |
|
420 |
|
421 // Now enable the write to complete, by ending the 'flow off' |
|
422 flowOff = EFalse; |
|
423 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
424 TESTL(KErrNone == ret); |
|
425 |
|
426 User::WaitForRequest(txStat); |
|
427 ++txCnt; |
|
428 txSize += txlen(); |
|
429 |
|
430 if(txStat!=KErrNone) |
|
431 { |
|
432 Logger().WriteFormat(_L("Error in sending packet : %d "), txStat.Int()); |
|
433 break; |
|
434 } |
|
435 RDebug::Printf("tx #%d, +%d\n", txCnt, txlen()); |
|
436 if(txSize >= KBufferLength) |
|
437 { |
|
438 txSentAll=ETrue; |
|
439 } |
|
440 } |
|
441 |
|
442 // receiving packets |
|
443 if((rxStat.Int() != KRequestPending) && !rxRecvAll) |
|
444 { |
|
445 RDebug::Printf("rx status:%d, ", rxStat.Int()); |
|
446 ++rxCnt; |
|
447 |
|
448 ptrreadbuf.Zero(); |
|
449 sock.RecvFrom(ptrreadbuf,destAddr, 0, rxStat, rxlen); |
|
450 User::WaitForRequest(rxStat); |
|
451 rxSize += ptrreadbuf.Length(); |
|
452 |
|
453 if(rxStat!=KErrNone) |
|
454 { |
|
455 Logger().WriteFormat(_L("Error in receiving packet : %d "), rxStat.Int()); |
|
456 break; |
|
457 } |
|
458 RDebug::Printf("rx #%d, +%d\n", rxCnt, ptrreadbuf.Length()); |
|
459 |
|
460 if(rxSize >= KBufferLength) |
|
461 { |
|
462 rxRecvAll=ETrue; |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 CleanupStack::PopAndDestroy(2, writebuf); // writebuf and readbuf |
|
468 CleanupStack::PopAndDestroy(2); // sock, ss |
|
469 |
|
470 SetTestStepResult(EPass); |
|
471 return TestStepResult(); |
|
472 } |
|
473 |
|
474 // Test step 31.4 |
|
475 // Sending more than 16k packets. |
|
476 // Datagram |
|
477 // Non-Blocking mode |
|
478 // |
|
479 const TDesC& CSocketTest31_4::GetTestName() |
|
480 { |
|
481 _LIT(ret,"Test31.4"); |
|
482 return ret; |
|
483 } |
|
484 |
|
485 enum TVerdict CSocketTest31_4::InternalDoTestStepL( void ) |
|
486 { |
|
487 TVerdict verdict = EPass; |
|
488 |
|
489 Logger().WriteFormat(_L("Test Purpose: Repeat send over 64K datagram using TSockXfrLength.")); |
|
490 |
|
491 // connect to esock |
|
492 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
493 RSocketServ ss; |
|
494 |
|
495 // protocol allowing unlimited datagram size |
|
496 TSessionPref pref; |
|
497 pref.iAddrFamily = KDummyAddrFamily; |
|
498 pref.iProtocol = KDummyFive; |
|
499 TInt ret = ss.Connect(pref); |
|
500 |
|
501 CleanupClosePushL(ss); |
|
502 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
503 TESTL(KErrNone == ret); |
|
504 |
|
505 Logger().WriteFormat(_L("Finding for dummy protocol 5")); |
|
506 TProtocolDesc protoInfo; |
|
507 ret = ss.FindProtocol(_L("Dummy Protocol 5"), protoInfo); |
|
508 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
509 TESTL(KErrNone == ret); |
|
510 |
|
511 Logger().WriteFormat(_L("Opening a socket")); |
|
512 RSocket sock; |
|
513 ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
514 CleanupClosePushL(sock); |
|
515 Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret)); |
|
516 TESTL(KErrNone == ret); |
|
517 |
|
518 TPckgBuf<TUint> lenbuf; |
|
519 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
520 ret = sock.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
521 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), |
|
522 &EpocErrorToText(ret), lenbuf()); |
|
523 TESTL(KErrNone == ret); |
|
524 |
|
525 TUint x(KBufferLength); |
|
526 lenbuf() = x; |
|
527 Logger().WriteFormat(_L("Setting SendBuf length to %d"), lenbuf()); |
|
528 ret = sock.SetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
529 Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret)); |
|
530 TESTL(KErrNone == ret); |
|
531 |
|
532 Logger().WriteFormat(_L("Getting SendBuf length")); |
|
533 ret = sock.GetOpt(KSOSendBuf, KSOLSocket, lenbuf); |
|
534 Logger().WriteFormat(_L("GetOpt returned %S, length %d"), &EpocErrorToText(ret), lenbuf()); |
|
535 TESTL(KErrNone == ret); |
|
536 TESTL(lenbuf() == x); |
|
537 |
|
538 // Setting option |
|
539 // Force the SendTo to 'flow off' |
|
540 TBool flowOff = ETrue; |
|
541 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
542 Logger().WriteFormat(_L("SetOpt (flow off) returned %S"), &EpocErrorToText(ret)); |
|
543 TESTL(KErrNone == ret); |
|
544 |
|
545 ret = sock.SetOpt(KSONonBlockingIO, KSOLSocket, 1); |
|
546 Logger().WriteFormat(_L("SetOpt NonBlockingIO returned %S"), &EpocErrorToText(ret)); |
|
547 TESTL(KErrNone == ret); |
|
548 |
|
549 Logger().WriteFormat(_L("Try sending datagram over protocol allowing unlimited datagram size")); |
|
550 TInetAddr destAddr; |
|
551 TRequestStatus status; |
|
552 |
|
553 // Setting up buffer |
|
554 HBufC8* writebuf = HBufC8::NewMaxLC(KBufferLength); |
|
555 HBufC8* readbuf = HBufC8::NewMaxLC(KBufferLength); |
|
556 |
|
557 TPtr8 ptrwritebuf(const_cast<TUint8*>(writebuf->Ptr()), KBufferLength); |
|
558 TPtr8 ptrreadbuf(const_cast<TUint8*>(readbuf->Ptr()), KBufferLength); |
|
559 |
|
560 ptrwritebuf.SetLength(ptrwritebuf.MaxLength()); |
|
561 ptrreadbuf.SetLength(ptrreadbuf.MaxLength()); |
|
562 |
|
563 // Filling buffer |
|
564 ptrwritebuf.Repeat(_L8("Datagram-packet: helloworld")); |
|
565 |
|
566 TRequestStatus txStat; |
|
567 TRequestStatus rxStat; |
|
568 TSockXfrLength txlen; |
|
569 TSockXfrLength rxlen; |
|
570 TInt txSize = 0, txCnt = 0;; |
|
571 TInt rxSize = 0, rxCnt = -1; |
|
572 TBool txSentAll = EFalse; |
|
573 TBool rxRecvAll = EFalse; |
|
574 |
|
575 while(rxSize < KBufferLength) |
|
576 { |
|
577 // sending packets |
|
578 if(txStat.Int() != KRequestPending && !txSentAll) |
|
579 { |
|
580 RDebug::Printf("tx status:%d, ", txStat.Int()); |
|
581 TPtrC8 ptrtempbuf(ptrwritebuf.Mid(txSize)); |
|
582 sock.SendTo(ptrtempbuf, destAddr, 0, txStat, txlen); |
|
583 |
|
584 // Now enable the write to complete, by ending the 'flow off' |
|
585 flowOff = EFalse; |
|
586 ret = sock.SetOpt(KDummyOptionSetFlowOffWrite, 0, flowOff); |
|
587 TESTL(KErrNone == ret); |
|
588 |
|
589 User::WaitForRequest(txStat); |
|
590 ++txCnt; |
|
591 txSize += txlen(); |
|
592 |
|
593 if(txStat!=KErrNone) |
|
594 { |
|
595 Logger().WriteFormat(_L("Error in sending packet : %d "), txStat.Int()); |
|
596 break; |
|
597 } |
|
598 RDebug::Printf("tx #%d, +%d\n", txCnt, txlen()); |
|
599 if(txSize >= KBufferLength) |
|
600 { |
|
601 txSentAll=ETrue; |
|
602 } |
|
603 } |
|
604 |
|
605 // receiving packets |
|
606 if((rxStat.Int() != KRequestPending) && !rxRecvAll) |
|
607 { |
|
608 RDebug::Printf("rx status:%d, ", rxStat.Int()); |
|
609 ++rxCnt; |
|
610 |
|
611 ptrreadbuf.Zero(); |
|
612 sock.RecvFrom(ptrreadbuf,destAddr, 0, rxStat, rxlen); |
|
613 User::WaitForRequest(rxStat); |
|
614 rxSize += ptrreadbuf.Length(); |
|
615 //rxSize += rxlen(); |
|
616 |
|
617 if(rxStat!=KErrNone && rxStat!=KErrWouldBlock) |
|
618 { |
|
619 Logger().WriteFormat(_L("Error in receiving packet : %d "), rxStat.Int()); |
|
620 break; |
|
621 } |
|
622 RDebug::Printf("rx #%d, +%d\n", rxCnt, ptrreadbuf.Length()); |
|
623 |
|
624 if(rxSize >= KBufferLength) |
|
625 { |
|
626 rxRecvAll=ETrue; |
|
627 } |
|
628 } |
|
629 } |
|
630 |
|
631 CleanupStack::PopAndDestroy(2, writebuf); // writebuf and readbuf |
|
632 CleanupStack::PopAndDestroy(2); // sock, ss |
|
633 |
|
634 SetTestStepResult(EPass); |
|
635 return TestStepResult(); |
|
636 } |
|
637 |