summaryrefslogtreecommitdiff
path: root/src/old/tests/connect.cpp
blob: a9fca64da4eac36cff78ff84e351ad082aadc97c (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "connection.h"

int main()
{
	Connection c;
	c.open("127.0.0.1", 12457 );

	{
		int newSocket = c.getSocket();
		int flags;

		flags = fcntl(newSocket, F_GETFL, 0);
		flags |= O_NONBLOCK;
		if (fcntl(newSocket, F_SETFL, flags) < 0)
		{
			return false;
		}
	}

	for( int i = 0; i < 50; i++ )
	{
		usleep( 100000 );
		int nbytes = c.readInput();
		if( nbytes == 0 )
			printf("0 bytes, EOF?\n");
		else
			printf("Got %d bytes, whacky...\n", nbytes );
	}

	c.close();

	return 0;
}