]> git.mxchange.org Git - simgear.git/blob - simgear/io/socktest.cxx
Various mingwin patches contributed by Norman Vine.
[simgear.git] / simgear / io / socktest.cxx
1 #include <simgear/compiler.h>
2
3 #include <unistd.h>
4 #include STL_IOSTREAM
5
6 #include "sg_socket.hxx"
7 #include "lowlevel.hxx"
8
9 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
10 SG_USING_STD(cout);
11 SG_USING_STD(endl);
12 #endif
13
14 static const int sgEndianTest = 1;
15 #define sgIsLittleEndian (*((char *) &sgEndianTest ) != 0)
16 #define sgIsBigEndian    (*((char *) &sgEndianTest ) == 0)
17
18 int main() {
19
20     if ( sgIsLittleEndian ) {
21        cout << "this machine is little endian\n";
22     }
23
24     if ( sgIsBigEndian ) {
25        cout << "this machine is big endian\n";
26     }
27
28     cout << "short = " << sizeof(unsigned short) << endl;
29     cout << "int = " << sizeof(unsigned int) << endl;
30     cout << "long long = " << sizeof(long long) << endl;
31
32     SGSocket s( "", "5500", "tcp" );
33
34     if ( !s.open( SG_IO_BI ) ) {
35         cout << "error can't open socket\n";
36     }
37
38     char buf[256];
39
40     while ( true ) {
41         if ( s.readline( buf, 256 ) > 0 ) {
42             cout << "result = " << buf;
43         }
44 #ifdef __MINGW32__
45         Sleep(100);
46 #else
47         sleep(1);
48 #endif
49     }
50 }