00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_UTILITY_H
00023 #define FIX_UTILITY_H
00024
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028
00029 #ifdef _MSC_VER
00030
00031 #include <Winsock2.h>
00032 #include <process.h>
00033 #include <direct.h>
00034 #include <time.h>
00035 typedef int socklen_t;
00037 #else
00038
00039 #include <sys/types.h>
00040 #include <sys/socket.h>
00041 #include <sys/ioctl.h>
00042 #include <sys/time.h>
00043 #include <sys/stat.h>
00044 #include <netinet/in.h>
00045 #include <netinet/tcp.h>
00046 #include <arpa/inet.h>
00047 #include <netdb.h>
00048 #include <fcntl.h>
00049 #include <unistd.h>
00050 #include <pthread.h>
00051 #include <signal.h>
00052 #include <errno.h>
00053 #include <time.h>
00055 #endif
00056
00057 #include <string>
00058 #include <cctype>
00059 #include <ctime>
00060
00061 namespace FIX
00062 {
00063 void string_replace( const std::string& oldValue,
00064 const std::string& newValue,
00065 std::string& value );
00066
00067 void socket_init();
00068 void socket_term();
00069 int socket_createAcceptor( int port, bool reuse = false );
00070 int socket_createConnector();
00071 int socket_connect( int s, const char* address, int port );
00072 int socket_accept( int s );
00073 int socket_send( int s, const char* msg, int length );
00074 void socket_close( int s );
00075 bool socket_fionread( int s, int& bytes );
00076 bool socket_disconnected( int s );
00077 int socket_setsockopt( int s, int opt );
00078 int socket_getsockopt( int s, int opt, int& optval );
00079 #ifndef _MSC_VER
00080 int socket_fcntl( int s, int opt, int arg );
00081 int socket_getfcntlflag( int s, int arg );
00082 int socket_setfcntlflag( int s, int arg );
00083 #endif
00084 void socket_setnonblock( int s );
00085 bool socket_isValid( int socket );
00086 #ifndef _MSC_VER
00087 bool socket_isBad( int s );
00088 #endif
00089 void socket_invalidate( int& socket );
00090 short socket_hostport( int socket );
00091 const char* socket_hostname( int socket );
00092 const char* socket_hostname( const char* name );
00093 const char* socket_peername( int socket );
00094 std::pair<int, int> socket_createpair();
00095
00096 tm time_gmtime( const time_t* t );
00097 tm time_localtime( const time_t* t);
00098
00099 #ifdef _MSC_VER
00100 typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
00101 #define THREAD_PROC unsigned int _stdcall
00102 #else
00103 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
00104 #define THREAD_PROC void *
00105 #endif
00106
00107 bool thread_spawn( THREAD_START_ROUTINE func, void* var, unsigned& thread );
00108 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
00109 void thread_join( unsigned thread );
00110 void thread_detach( unsigned thread );
00111 unsigned thread_self();
00112
00113 void process_sleep( double s );
00114
00115 std::string file_separator();
00116 #ifdef _MSC_VER
00117 void file_mkdir( const char* path );
00118 #else
00119 void file_mkdir( const char* path );
00120 #endif
00121 FILE* file_fopen( const char* path, const char* mode );
00122 void file_unlink( const char* path );
00123 std::string file_appendpath( const std::string& path, const std::string& file );
00124 }
00125
00126 #if( _MSC_VER >= 1400 )
00127 #define HAVE_FSCANF_S 1
00128 #define FILE_FSCANF fscanf_s
00129 #else
00130 #define FILE_FSCANF fscanf
00131 #endif
00132
00133 #if( _MSC_VER >= 1400 )
00134 #define HAVE_SPRINTF_S 1
00135 #define STRING_SPRINTF sprintf_s
00136 #else
00137 #define STRING_SPRINTF sprintf
00138 #endif
00139
00140 #if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
00141 using std::abort;
00142 using std::sprintf;
00143 using std::atoi;
00144 using std::atol;
00145 using std::atof;
00146 using std::isdigit;
00147 using std::strcmp;
00148 using std::strftime;
00149 using std::strlen;
00150 using std::abs;
00151 using std::labs;
00152 using std::memcpy;
00153 using std::memset;
00154 using std::exit;
00155 #endif
00156
00157 #endif