aboutsummaryrefslogtreecommitdiff
path: root/src/tests/socketblock.cpp
blob: e36bb33cafd03a7704c766b1624ac11d60948e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/ito.h"
#include "bu/tcpsocket.h"
#include "bu/tcpserversocket.h"
#include <stdio.h>
#include <unistd.h>

class TstServer : public Bu::Ito
{
public:
	TstServer() :
		s( 55678 )
	{
	}

	virtual void run()
	{
		Bu::TcpSocket c = s.accept( 45, 0 );
		printf("TstServer:  Accetped connection.\n"); fflush( stdout );
		
		sleep( 1 );
		printf("TstServer:  Trying to read 10 bytes...\n"); fflush( stdout );

		char buf[10];
		size_t nRead = c.read( buf, 10 );
		printf("TstServer:  Got %d bytes...\n", nRead ); fflush( stdout );

		printf("TstServer:  Closing connection...\n"); fflush( stdout );
		c.close();
	}

	Bu::TcpServerSocket s;
};

int main()
{
	TstServer ts;

	ts.start();

	printf("main:  Connecting to server.\n"); fflush( stdout );
	Bu::TcpSocket s( "localhost", 55678 );

	printf("main:  Sending 4 bytes.\n"); fflush( stdout );
	s.write( "aoeu", 4 );

	printf("main:  Sleeping 10 seconds for good measure.\n"); fflush( stdout );
	sleep( 10 );
}