os/ossrv/genericopenlibs/cstdlib/TSTLIB/TLSTREAM.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
* Test of AF_LOCAL stream sockets
sl@0
    16
* 
sl@0
    17
*
sl@0
    18
*/
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
#include <stdio.h>
sl@0
    23
#include <errno.h>
sl@0
    24
#include <stdlib.h>
sl@0
    25
#include <string.h>
sl@0
    26
#include <unistd.h>
sl@0
    27
#include <sys/types.h>
sl@0
    28
#include <sys/socket.h>
sl@0
    29
#include <sys/ioctl.h>
sl@0
    30
sl@0
    31
#include "ctest.h"	/* includes C interface to EPOC32 threads, and SpawnPosixServer */
sl@0
    32
sl@0
    33
test_Data;
sl@0
    34
sl@0
    35
/**
sl@0
    36
@SYMTestCaseID          SYSLIB-STDLIB-CT-1115
sl@0
    37
@SYMTestCaseDesc	    Tests for AF_LOCAL stream sockets
sl@0
    38
@SYMTestPriority 	    High
sl@0
    39
@SYMTestActions  	    Tests for create socket,binding and other simple socket operations
sl@0
    40
@SYMTestExpectedResults Test must not fail
sl@0
    41
@SYMREQ                 REQ0000
sl@0
    42
*/					
sl@0
    43
void testSimple()
sl@0
    44
	{
sl@0
    45
	int fd1, fd2;
sl@0
    46
	size_t addrsize;
sl@0
    47
	int err;
sl@0
    48
	struct sockaddr addr1, addr2;
sl@0
    49
	int optionbuf[20];
sl@0
    50
	size_t optionsize;
sl@0
    51
sl@0
    52
	test_Next("Create stream sockets");
sl@0
    53
	fd1=socket(AF_LOCAL, SOCK_STREAM, 0);
sl@0
    54
	test_ok(fd1>=0);
sl@0
    55
sl@0
    56
	fd2=socket(AF_LOCAL, SOCK_STREAM, 0);
sl@0
    57
	test_ok(fd2>=0);
sl@0
    58
sl@0
    59
	test_Next("Some binding tests");
sl@0
    60
sl@0
    61
#if 0 /* causes socket server panic with ESOCK 058 */
sl@0
    62
	addr1.sa_family=AF_UNSPEC;
sl@0
    63
	addr1.sa_port=65530;
sl@0
    64
	err=bind(fd1,&addr1, sizeof(addr1));	/* wrong family, port out of range */
sl@0
    65
	test_ok(err!=0);
sl@0
    66
#endif
sl@0
    67
sl@0
    68
	addr1.sa_family=AF_LOCAL;
sl@0
    69
	addr1.sa_port=1;
sl@0
    70
	err=bind(fd1, &addr1, sizeof(addr1));
sl@0
    71
	test_ok(err==0);
sl@0
    72
sl@0
    73
	addr1.sa_family=AF_LOCAL;
sl@0
    74
	addr1.sa_port=2;
sl@0
    75
	err=bind(fd1, &addr1, sizeof(addr1));	/* already bound */
sl@0
    76
	test_errno(err!=0, EEXIST);
sl@0
    77
sl@0
    78
	test_Next("Get associated addresses");
sl@0
    79
sl@0
    80
	addrsize=sizeof(addr2);
sl@0
    81
	err=getsockname(fd1,&addr2,&addrsize);
sl@0
    82
	test_ok(err==0);
sl@0
    83
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
    84
	test(addr2.sa_port==1);
sl@0
    85
	test(addrsize<=sizeof(addr2));
sl@0
    86
sl@0
    87
	addrsize=sizeof(addr2);
sl@0
    88
	err=getpeername(fd1,&addr2,&addrsize);	/* not connected */
sl@0
    89
	test_errno(err!=0,-2);	/* OMISSION - can't report proper reason for failure */
sl@0
    90
sl@0
    91
	addrsize=sizeof(addr2);
sl@0
    92
	err=getsockname(fd2,&addr2,&addrsize);	/* not bound */
sl@0
    93
	test_errno(err!=0,-2);	/* OMISSION - can't report proper reason for failure */
sl@0
    94
sl@0
    95
	test_Next("More binding");
sl@0
    96
sl@0
    97
	addr1.sa_family=AF_LOCAL;
sl@0
    98
	addr1.sa_port=1;
sl@0
    99
	err=bind(fd2, &addr1, sizeof(addr1));	/* address in use */
sl@0
   100
	test_errno(err!=0, EACCES);
sl@0
   101
sl@0
   102
#if 0	/* this isn't supported by AF_LOCAL */
sl@0
   103
	addr1.sa_family=AF_LOCAL;
sl@0
   104
	addr1.sa_port=0;
sl@0
   105
	err=bind(fd2, &addr1, sizeof(addr1));	/* unspecified port number */
sl@0
   106
	test_ok(err==0);
sl@0
   107
sl@0
   108
	addrsize=sizeof(addr2);
sl@0
   109
	err=getsockname(fd2,&addr2,&addrsize);
sl@0
   110
	test_ok(err==0);
sl@0
   111
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   112
	test(addr2.sa_port!=1);
sl@0
   113
	test(addr2.sa_port!=0);
sl@0
   114
	test(addrsize<=sizeof(addr2));
sl@0
   115
#endif
sl@0
   116
sl@0
   117
	err=listen(fd1,1);
sl@0
   118
	test_ok(err==0);
sl@0
   119
sl@0
   120
	test_Next("Socket options");
sl@0
   121
sl@0
   122
	optionbuf[0]=3500000;	/* implausible size */
sl@0
   123
	optionsize=sizeof(optionbuf[0]);
sl@0
   124
	err=getsockopt(fd1,SOL_SOCKET,SO_SNDBUF,optionbuf,&optionsize);
sl@0
   125
	test_ok(err==0);
sl@0
   126
	test(optionbuf[0]!=3500000);
sl@0
   127
sl@0
   128
	optionbuf[0]=7*1024;
sl@0
   129
	optionsize=sizeof(optionbuf[0]);
sl@0
   130
	err=setsockopt(fd1,SOL_SOCKET,SO_SNDBUF,optionbuf,optionsize);
sl@0
   131
	test_ok(err==0);
sl@0
   132
sl@0
   133
	optionbuf[0]=3500000;	/* implausible size */
sl@0
   134
	optionsize=sizeof(optionbuf[0]);
sl@0
   135
	err=getsockopt(fd1,SOL_SOCKET,SO_SNDBUF,optionbuf,&optionsize);
sl@0
   136
	test_ok(err==0);
sl@0
   137
	test(optionbuf[0]==7*1024);
sl@0
   138
sl@0
   139
	optionbuf[0]=1;
sl@0
   140
	optionsize=sizeof(optionbuf[0]);
sl@0
   141
	err=getsockopt(fd1,SOL_SOCKET,1234,optionbuf,&optionsize);	/* invalid option */
sl@0
   142
	test_errno(err<0,ENOSYS);
sl@0
   143
	test(optionbuf[0]==1);
sl@0
   144
sl@0
   145
	optionbuf[0]=13;
sl@0
   146
	optionsize=sizeof(optionbuf[0]);
sl@0
   147
	err=setsockopt(fd1,SOL_SOCKET,1234,optionbuf,optionsize);	/* invalid option */
sl@0
   148
	test_errno(err<0,ENOSYS);
sl@0
   149
	test(optionbuf[0]==13);
sl@0
   150
sl@0
   151
	err=close(fd1);
sl@0
   152
	test_ok(err==0);
sl@0
   153
sl@0
   154
	err=close(fd2);
sl@0
   155
	test_ok(err==0);
sl@0
   156
	}
sl@0
   157
sl@0
   158
/* Client and server take it in turns to send, starting with the client.
sl@0
   159
 * Each matches the message they receive with the string expected
sl@0
   160
 */
sl@0
   161
char *message_sequence[] = {
sl@0
   162
	"Hello from client",
sl@0
   163
	"Hello from server",
sl@0
   164
	"Test of send",
sl@0
   165
	"Test of recv",
sl@0
   166
	"Try sendto",
sl@0
   167
	"Try recvfrom",
sl@0
   168
	"Send to shutdown socket",
sl@0
   169
	"Send to closed socket",
sl@0
   170
	0
sl@0
   171
	};
sl@0
   172
sl@0
   173
/**
sl@0
   174
@SYMTestCaseID          SYSLIB-STDLIB-CT-1116
sl@0
   175
@SYMTestCaseDesc	    Tests for server socket
sl@0
   176
@SYMTestPriority 	    High
sl@0
   177
@SYMTestActions  	    Tests for server socket,create,accept,send and receive functions
sl@0
   178
@SYMTestExpectedResults Test must not fail
sl@0
   179
@SYMREQ                 REQ0000
sl@0
   180
*/					
sl@0
   181
void testServer()
sl@0
   182
	{
sl@0
   183
	int fd1, fd2, nbytes, i;
sl@0
   184
	size_t addrsize;
sl@0
   185
	int err;
sl@0
   186
	struct sockaddr addr1, addr2;
sl@0
   187
	char buf[80];
sl@0
   188
	char **mp = message_sequence;
sl@0
   189
sl@0
   190
	test_Next("Create server socket");
sl@0
   191
	fd1=socket(AF_LOCAL, SOCK_STREAM, 0);
sl@0
   192
	test_ok(fd1>=0);
sl@0
   193
sl@0
   194
#if 0
sl@0
   195
	/* causes ESOCK to panic the client */
sl@0
   196
	addrsize=sizeof(addr2);
sl@0
   197
	fd2=accept(fd1,&addr2,&addrsize);	/* can't accept on an unbound socket */
sl@0
   198
	test_ok(fd2<0);
sl@0
   199
#endif
sl@0
   200
sl@0
   201
	addr1.sa_family=AF_LOCAL;
sl@0
   202
	addr1.sa_port=1;
sl@0
   203
	err=bind(fd1, &addr1, sizeof(addr1));
sl@0
   204
	test_ok(err==0);
sl@0
   205
sl@0
   206
#if 0
sl@0
   207
	/* causes ESOCK to panic the client */
sl@0
   208
	addrsize=sizeof(addr2);
sl@0
   209
	fd2=accept(fd1,&addr2,&addrsize);	/* can't accept before listening */
sl@0
   210
	test_ok(fd2<0);
sl@0
   211
#endif
sl@0
   212
sl@0
   213
	err=listen(fd1,1);
sl@0
   214
	test_ok(err==0);
sl@0
   215
sl@0
   216
	addrsize=sizeof(addr2);
sl@0
   217
	fd2=accept(fd1,&addr2,&addrsize);
sl@0
   218
	test_ok(fd2>=0);
sl@0
   219
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   220
	test(addr2.sa_port!=1);
sl@0
   221
	test(addr2.sa_port!=0);
sl@0
   222
	test(addrsize<=sizeof(addr2));
sl@0
   223
sl@0
   224
	test_Next("Server read/write");
sl@0
   225
sl@0
   226
	/* read */
sl@0
   227
	nbytes=strlen(*mp);
sl@0
   228
	err=read(fd2, buf, nbytes+1);
sl@0
   229
	test_ok(err==nbytes+1);
sl@0
   230
	test(strcmp(buf,*mp)==0);
sl@0
   231
sl@0
   232
	/* write */
sl@0
   233
	mp++;
sl@0
   234
	nbytes=strlen(*mp);
sl@0
   235
	for (i=0; i<nbytes+1; i++)
sl@0
   236
		{
sl@0
   237
		err=write(fd2,(*mp)+i,1);
sl@0
   238
		test_ok(err==1);
sl@0
   239
		}
sl@0
   240
sl@0
   241
	test_Next("Server send/recv");
sl@0
   242
sl@0
   243
	/* recv */
sl@0
   244
	mp++;
sl@0
   245
	nbytes=strlen(*mp);
sl@0
   246
	err=recv(fd2, buf, nbytes+1,0);
sl@0
   247
	test_ok(err==nbytes+1);
sl@0
   248
	test(strcmp(buf,*mp)==0);
sl@0
   249
sl@0
   250
	/* send */
sl@0
   251
	mp++;
sl@0
   252
	nbytes=strlen(*mp);
sl@0
   253
	err=send(fd2, *mp, nbytes+1,0);
sl@0
   254
	test_ok(err==nbytes+1);
sl@0
   255
sl@0
   256
	/* recvfrom */
sl@0
   257
	mp++;
sl@0
   258
	nbytes=strlen(*mp);
sl@0
   259
	addrsize=sizeof(addr2);
sl@0
   260
	addr2.sa_port=0;
sl@0
   261
	err=recvfrom(fd2, buf, nbytes+1,0,&addr2,&addrsize);
sl@0
   262
	test_ok(err==nbytes+1);
sl@0
   263
	test(strcmp(buf,*mp)==0);
sl@0
   264
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   265
	test(addr2.sa_port!=1);
sl@0
   266
	test(addr2.sa_port!=0);
sl@0
   267
	test(addrsize<=sizeof(addr2));
sl@0
   268
sl@0
   269
	/* sendto */
sl@0
   270
	mp++;
sl@0
   271
	nbytes=strlen(*mp);
sl@0
   272
	addrsize=sizeof(addr1);
sl@0
   273
	err=sendto(fd2, *mp, nbytes+1,0,&addr1,addrsize);	/* not allowed on streams */
sl@0
   274
	test_errno(err<0,ENOSYS);
sl@0
   275
	err=send(fd2, *mp, nbytes+1,0);		/* to keep synchronisation */
sl@0
   276
	test_ok(err==nbytes+1);
sl@0
   277
sl@0
   278
	test_Next("Server shutdown reception");
sl@0
   279
	err=shutdown(fd2,0);
sl@0
   280
	test_ok(err==0);
sl@0
   281
sl@0
   282
	sleep(2);	/* so that the client's sleep(1) finishes before we awake */
sl@0
   283
sl@0
   284
	err=close(fd2);
sl@0
   285
	test_ok(err==0);
sl@0
   286
sl@0
   287
	err=close(fd1);
sl@0
   288
	test_ok(err==0);
sl@0
   289
	}
sl@0
   290
sl@0
   291
/**
sl@0
   292
@SYMTestCaseID          SYSLIB-STDLIB-CT-1117
sl@0
   293
@SYMTestCaseDesc	    Tests for client socket
sl@0
   294
@SYMTestPriority 	    High
sl@0
   295
@SYMTestActions  	    Tests for client socket,create,accept,send and receive functions
sl@0
   296
                        Write to a connection closed socket and test for error
sl@0
   297
@SYMTestExpectedResults Test must not fail
sl@0
   298
@SYMREQ                 REQ0000
sl@0
   299
*/					
sl@0
   300
void testClient()
sl@0
   301
	{
sl@0
   302
	int fd1, nbytes, nbytes2, i, status;
sl@0
   303
	size_t addrsize;
sl@0
   304
	int err;
sl@0
   305
	struct sockaddr addr1, addr2;
sl@0
   306
	char buf[80];
sl@0
   307
	char **mp = message_sequence;
sl@0
   308
sl@0
   309
	test_Next("Create client socket");
sl@0
   310
	fd1=socket(AF_LOCAL, SOCK_STREAM, 0);
sl@0
   311
	test_ok(fd1>=0);
sl@0
   312
sl@0
   313
	addr1.sa_family=AF_LOCAL;
sl@0
   314
	addr1.sa_port=1;
sl@0
   315
	addrsize=sizeof(addr1);
sl@0
   316
	err=connect(fd1,&addr1,addrsize);
sl@0
   317
	test_ok(err==0);
sl@0
   318
sl@0
   319
	addrsize=sizeof(addr2);
sl@0
   320
	err=getpeername(fd1,&addr2,&addrsize);
sl@0
   321
	test_ok(err==0);
sl@0
   322
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   323
	test(addr2.sa_port==1);
sl@0
   324
	test(addrsize<=sizeof(addr2));
sl@0
   325
sl@0
   326
	addrsize=sizeof(addr2);
sl@0
   327
	err=getsockname(fd1,&addr2,&addrsize);
sl@0
   328
	test_ok(err==0);
sl@0
   329
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   330
	test(addr2.sa_port!=1);
sl@0
   331
	test(addr2.sa_port!=0);
sl@0
   332
	test(addrsize<=sizeof(addr2));
sl@0
   333
sl@0
   334
	test_Next("Client read/write");
sl@0
   335
sl@0
   336
	/* write */
sl@0
   337
	nbytes=strlen(*mp);
sl@0
   338
	err=write(fd1, *mp, nbytes+1);
sl@0
   339
	test_ok(err==nbytes+1);
sl@0
   340
sl@0
   341
	/* read */
sl@0
   342
	mp++;
sl@0
   343
	nbytes=strlen(*mp);
sl@0
   344
	err=read(fd1, buf, nbytes+1);
sl@0
   345
	test_ok(err==nbytes+1);
sl@0
   346
	test(strcmp(buf,*mp)==0);
sl@0
   347
sl@0
   348
	test_Next("Client send/recv");
sl@0
   349
sl@0
   350
	/* send */
sl@0
   351
	mp++;
sl@0
   352
	nbytes=strlen(*mp);
sl@0
   353
	for (i=0; i<nbytes+1; i++)
sl@0
   354
		{
sl@0
   355
		err=send(fd1,(*mp)+i,1,0);
sl@0
   356
		test_ok(err==1);
sl@0
   357
		}
sl@0
   358
sl@0
   359
	/* recv - get the first byte so that we know the buffer is full */
sl@0
   360
	mp++;
sl@0
   361
	nbytes=strlen(*mp);
sl@0
   362
	err=recv(fd1,buf,1,0);
sl@0
   363
	test_ok(err==1);
sl@0
   364
sl@0
   365
	/* ioctl */
sl@0
   366
	nbytes2=-1;
sl@0
   367
	err=ioctl(fd1,E32IONREAD,&nbytes2);
sl@0
   368
#if 0
sl@0
   369
	test_ok(err==0);
sl@0
   370
	test(nbytes2==nbytes);
sl@0
   371
#else
sl@0
   372
	test_errno(err<0,ENOSYS);	/* IPC.PRT doesn't implement KSoReadBytesPending */
sl@0
   373
#endif
sl@0
   374
sl@0
   375
	nbytes2=E32SELECT_READ|E32SELECT_WRITE|E32SELECT_EXCEPT;
sl@0
   376
	err=ioctl(fd1,E32IOSELECT,&nbytes2);
sl@0
   377
	test_ok(err==0);
sl@0
   378
	test(nbytes2==(E32SELECT_READ|E32SELECT_WRITE));
sl@0
   379
sl@0
   380
	nbytes2=E32SELECT_READ|E32SELECT_WRITE|E32SELECT_EXCEPT;
sl@0
   381
	err=async_ioctl(fd1,E32IOSELECT,&nbytes2,&status);
sl@0
   382
	test_ok(err==0);
sl@0
   383
	err=async_ioctl_completion(fd1,E32IOSELECT,&nbytes2,&status);
sl@0
   384
	test_ok(err==0);
sl@0
   385
	if (nbytes2!=(E32SELECT_READ|E32SELECT_WRITE))
sl@0
   386
		{
sl@0
   387
		nbytes2=E32SELECT_READ|E32SELECT_WRITE|E32SELECT_EXCEPT;
sl@0
   388
		err=ioctl(fd1,E32IOSELECT,&nbytes2);
sl@0
   389
		test_ok(err==0);
sl@0
   390
		test(nbytes2==(E32SELECT_READ|E32SELECT_WRITE));
sl@0
   391
		}		
sl@0
   392
sl@0
   393
	/* recv - get the rest of the data */
sl@0
   394
	for (i=1; i<nbytes+1; i++)
sl@0
   395
		{
sl@0
   396
		err=recv(fd1,buf+i,1,0);
sl@0
   397
		test_ok(err==1);
sl@0
   398
		}
sl@0
   399
	test(strcmp(buf,*mp)==0);
sl@0
   400
sl@0
   401
	/* ioctl again - this time there is no data pending */
sl@0
   402
	nbytes2=-1;
sl@0
   403
	err=ioctl(fd1,E32IONREAD,&nbytes2);
sl@0
   404
#if 0
sl@0
   405
	test_ok(err==0);
sl@0
   406
	test(nbytes2==0);
sl@0
   407
#else
sl@0
   408
	test_errno(err<0,ENOSYS);	/* IPC.PRT doesn't implement KSoReadBytesPending */
sl@0
   409
#endif
sl@0
   410
sl@0
   411
	nbytes2=E32SELECT_READ|E32SELECT_WRITE|E32SELECT_EXCEPT;
sl@0
   412
	err=ioctl(fd1,E32IOSELECT,&nbytes2);
sl@0
   413
	test_ok(err==0);
sl@0
   414
	test(nbytes2==E32SELECT_WRITE);
sl@0
   415
sl@0
   416
	nbytes2=E32SELECT_READ|E32SELECT_WRITE|E32SELECT_EXCEPT;
sl@0
   417
	err=async_ioctl(fd1,E32IOSELECT,&nbytes2,&status);
sl@0
   418
	test_ok(err==0);
sl@0
   419
	err=async_ioctl_completion(fd1,E32IOSELECT,&nbytes2,&status);
sl@0
   420
	test_ok(err==0);
sl@0
   421
	test(nbytes2==E32SELECT_WRITE);
sl@0
   422
sl@0
   423
	/* sendto */
sl@0
   424
	mp++;
sl@0
   425
	nbytes=strlen(*mp);
sl@0
   426
	addrsize=sizeof(addr1);
sl@0
   427
	err=sendto(fd1, *mp, nbytes+1,0,&addr1,addrsize);
sl@0
   428
	test_errno(err<0,ENOSYS);
sl@0
   429
	err=send(fd1, *mp, nbytes+1,0);		/* to keep synchronisation */
sl@0
   430
	test_ok(err==nbytes+1);
sl@0
   431
sl@0
   432
	/* recvfrom */
sl@0
   433
	mp++;
sl@0
   434
	nbytes=strlen(*mp);
sl@0
   435
	addrsize=sizeof(addr2);
sl@0
   436
	addr2.sa_port=0;
sl@0
   437
	err=recvfrom(fd1, buf, nbytes+1,0,&addr2,&addrsize);
sl@0
   438
	test_ok(err==nbytes+1);
sl@0
   439
	test(strcmp(buf,*mp)==0);
sl@0
   440
	/* test(addr2.sa_family==AF_LOCAL);	problem in IPC.PRT, for ESOCK 058 */
sl@0
   441
	test(addr2.sa_port==1);
sl@0
   442
	test(addrsize<=sizeof(addr2));
sl@0
   443
sl@0
   444
	sleep(1);
sl@0
   445
sl@0
   446
	test_Next("Client write to closed connection");
sl@0
   447
sl@0
   448
	/* write to half-closed socket */
sl@0
   449
	mp++;
sl@0
   450
	nbytes=strlen(*mp);
sl@0
   451
	err=write(fd1, *mp, nbytes+1);
sl@0
   452
#if 0
sl@0
   453
	/* IPC doesn't seem to care! */
sl@0
   454
	test_errno(err<0, EPIPE);
sl@0
   455
#else
sl@0
   456
	test_ok(err==nbytes+1);
sl@0
   457
#endif
sl@0
   458
sl@0
   459
	sleep(2);	
sl@0
   460
	
sl@0
   461
	/* write to a connection closed by the other end */
sl@0
   462
	mp++;
sl@0
   463
	nbytes=strlen(*mp);
sl@0
   464
	err=write(fd1, *mp, nbytes+1);
sl@0
   465
	test_errno(err<0, EPIPE);
sl@0
   466
sl@0
   467
	err=close(fd1);
sl@0
   468
	test_ok(err==0);
sl@0
   469
	}
sl@0
   470
sl@0
   471
int close_console=0;
sl@0
   472
sl@0
   473
/**
sl@0
   474
@SYMTestCaseID          SYSLIB-STDLIB-CT-1118
sl@0
   475
@SYMTestCaseDesc	    Tests for STREAM server
sl@0
   476
@SYMTestPriority 	    High
sl@0
   477
@SYMTestActions  	    Tests for server entity
sl@0
   478
@SYMTestExpectedResults Test must not fail
sl@0
   479
@SYMREQ                 REQ0000
sl@0
   480
*/					
sl@0
   481
void testConnection()
sl@0
   482
	{
sl@0
   483
	int err;
sl@0
   484
	void* server;
sl@0
   485
	
sl@0
   486
	server=create_thread(testServer, "TLSTREAM server");
sl@0
   487
	test(server!=0);
sl@0
   488
	start_thread(server);
sl@0
   489
sl@0
   490
	sleep(1);	/* give the server a chance to get started */
sl@0
   491
	testClient();
sl@0
   492
sl@0
   493
	err=wait_for_thread(server);
sl@0
   494
	test(err==0);
sl@0
   495
sl@0
   496
	if (close_console)
sl@0
   497
		{
sl@0
   498
		test_Close();
sl@0
   499
		close(0);
sl@0
   500
		close(1);
sl@0
   501
		close(2);
sl@0
   502
		}
sl@0
   503
	}
sl@0
   504
sl@0
   505
int main(int argc, char *argv[])
sl@0
   506
	{
sl@0
   507
	void* client;
sl@0
   508
	int err;
sl@0
   509
sl@0
   510
	test_Title("AF_LOCAL Streams");
sl@0
   511
sl@0
   512
	testSimple();
sl@0
   513
	testConnection();
sl@0
   514
sl@0
   515
	test_Next("Do it again using the CPosixServer (for them, not me)");
sl@0
   516
	close_console=1;
sl@0
   517
sl@0
   518
	start_posix_server();	/* calls SpawnPosixServer from C++ code */
sl@0
   519
sl@0
   520
	client=create_thread(testSimple, "TLSTREAM simple");
sl@0
   521
	test(client!=0);
sl@0
   522
	start_thread(client);
sl@0
   523
	err=wait_for_thread(client);
sl@0
   524
	test(err==0);
sl@0
   525
sl@0
   526
	client=create_thread(testConnection, "TLSTREAM client");
sl@0
   527
	test(client!=0);
sl@0
   528
	start_thread(client);
sl@0
   529
	err=wait_for_thread(client);
sl@0
   530
	test(err==0);
sl@0
   531
sl@0
   532
	test_Close();
sl@0
   533
	return 0;
sl@0
   534
	}