Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

socket_ew.c

Go to the documentation of this file.
00001 
00002 /*
00003  *   THIS FILE IS UNDER RCS - DO NOT MODIFY UNLESS YOU HAVE
00004  *   CHECKED IT OUT USING THE COMMAND CHECKOUT.
00005  *
00006  *    $Id: socket__ew_8c-source.html 2161 2006-05-19 16:55:03Z paulf $
00007  *
00008  *    Revision history:
00009  *     $Log$
00009  *     Revision 1.1  2006/05/19 16:55:02  paulf
00009  *     first inclusion
00009  *
00010  *     Revision 1.1  2000/02/14 18:53:30  lucky
00011  *     Initial revision
00012  *
00013  *
00014  */
00015 
00016             /**********************************************************
00017              *               socket_ew.c for Windows NT               *
00018              *                                                        *
00019              *  Contains system-dependent functions for dealing with  *
00020              *  sockets.                                              *
00021              **********************************************************/
00022 
00023 #include <stdlib.h>
00024 #include <windows.h>  /* Includes winsock(2).h For Socket stuff */
00025 #include <earthworm.h>
00026 #include <socket_ew.h>
00027 
00028 int SOCKET_SYS_INIT = 0;   /* Global initialization flag,
00029                               set in SocketSysInit(), 
00030                               checked in socket_ew()  */
00031 
00032 /********************** SocketSysInit ********************
00033  *              Initialize the socket system             *
00034  *         We are using Windows socket version 2.2.      *
00035  *********************************************************/
00036 
00037 void SocketSysInit( void )
00038 {
00039    int     status;
00040    WSADATA Data;
00041 
00042    status = WSAStartup( MAKEWORD(2,2), &Data );
00043    if ( status != 0 )
00044    {
00045       logit( "et", "WSAStartup failed. Exitting.\n" );
00046       exit( -1 );
00047    }
00048    SOCKET_SYS_INIT++;
00049 
00050    logit( "t", "Socket version (wHighVersion): %x\n", Data.wHighVersion );
00051    return;
00052 }
00053 
00054 
00055 /********************** SocketClose **********************
00056  *                    Close a Socket                     *
00057  *********************************************************/
00058 
00059 void SocketClose( int soko )
00060 {
00061    if ( closesocket( (SOCKET)soko ) != 0 )
00062       SocketPerror( "SocketClose()" );
00063    return;
00064 }
00065 
00066 
00067 /********************** SocketPerror *********************
00068  *                Print an error message                 *
00069  *********************************************************/
00070 
00071 void SocketPerror( char *note )
00072 {
00073    logit( "et", "%s  Error %d encountered.\n", note, socketGetError_ew() );
00074    return;
00075 }
00076 
00077 
00078 /************************ sendall() ***********************
00079 *       looks like the standard send(), but does not      *
00080 *       return until either error, or all has been sent   *
00081 *       Also, we break sends into lumps as some           *
00082 *       implementations can't send too much at once.      *
00083 *       Will found this out.
00084 ***********************************************************/
00085 
00086 #define SENDALL_MAX_LUMP 1024   /* no send() larger  than this */
00087 
00088 int sendall(int socket, const char *msg, long msgLen, int flags)
00089 {
00090         int   ret;  /* number of bytes actually sent, or error */
00091         long  nextByte;
00092         int   nsend;
00093 
00094         nsend = SENDALL_MAX_LUMP; /* try sending in lumps of this size */
00095         nextByte = 0;
00096 
00097         while ( nextByte<msgLen )
00098                 {
00099                 if ( msgLen-nextByte < nsend ) nsend = msgLen-nextByte; /* last small send? */
00100                 ret = send(socket, (const char*)&msg[nextByte], nsend, flags);
00101                 if (ret < 0)
00102                         {
00103                         logit("t","send error %d\n",ret);
00104                         return( ret );
00105                         }
00106                 nextByte += ret;  /* we actually sent only this many */
00107                 }
00108         return ( msgLen );
00109 }
00110 
00111 
00112 /****************** socketGetError_ew *********************
00113      Returns the error code for the most recent socket error.
00114 **********************************************************/
00115 int socketGetError_ew()
00116 {
00117   int bob=(int)WSAGetLastError();
00118   return((int)WSAGetLastError());
00119 }
00120 
00121 
00122 Time_ew GetTime_ew()
00123 {
00124   FILETIME CurrentTime;
00125   Time_ew tewCurrentTime;
00126   DWORD * CTptr;
00127 
00128   GetSystemTimeAsFileTime(&CurrentTime);
00129   /* I saw some wierd things with 64 bit integers, so I'm kind of
00130      scared to cast this, since I know it works right now.  DK */
00131   CTptr=&tewCurrentTime;
00132   *CTptr=CurrentTime.dwLowDateTime;
00133   CTptr=(unsigned long *)(((int)CTptr) + 4);
00134   *CTptr=CurrentTime.dwHighDateTime;
00135   return(tewCurrentTime);
00136 }
00137 
00138 
00139 Time_ew adjustTimeoutLength(int timeout_msec)
00140 {
00141   return(((Time_ew)timeout_msec) * 10000); /* Convert miliseconds to
00142                                               100-nanoseconds */
00143 }
00144  
00145 

Generated on Tue May 6 09:16:10 2003 for Earthworm Libs by doxygen1.3-rc3