# inetsocket.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: inetsocket.h,v $
    00003                              -------------------
    00004     cvs         : $Id: inetsocket.h,v 1.13 2004/08/02 02:49:03 aquamaniac Exp $
    00005     begin       : Tue Oct 02 2002
    00006     copyright   : (C) 2002 by Martin Preuss
    00007     email       : martin@libchipcard.de
    00008
    00009  ***************************************************************************
    00010  *                                                                         *
    00011  *   This library is free software; you can redistribute it and/or         *
    00012  *   modify it under the terms of the GNU Lesser General Public            *
    00013  *   License as published by the Free Software Foundation; either          *
    00014  *   version 2.1 of the License, or (at your option) any later version.    *
    00015  *                                                                         *
    00016  *   This library is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
    00019  *   Lesser General Public License for more details.                       *
    00020  *                                                                         *
    00021  *   You should have received a copy of the GNU Lesser General Public      *
    00022  *   License along with this library; if not, write to the Free Software   *
    00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
    00024  *   MA  02111-1307  USA                                                   *
    00025  *                                                                         *
    00026  ***************************************************************************/
    00027
    00033 #ifndef GWEN_SOCKET_H
    00034 #define GWEN_SOCKET_H
    00035
    00036 #include <gwenhywfar/gwenhywfarapi.h>
    00037 #include "gwenhywfar/error.h"
    00038 #include <gwenhywfar/inetaddr.h>
    00039
    00040 #ifdef __cplusplus
    00041 extern "C" {
    00042 #endif
    00043
    00044
    00055 #define GWEN_SOCKET_ERROR_TYPE "Socket"
    00056 #define GWEN_SOCKET_ERROR_BAD_SOCKETTYPE (-1)
    00057 #define GWEN_SOCKET_ERROR_NOT_OPEN       (-2)
    00058 #define GWEN_SOCKET_ERROR_TIMEOUT        (-3)
    00059 #define GWEN_SOCKET_ERROR_IN_PROGRESS    (-4)
    00060 #define GWEN_SOCKET_ERROR_STARTUP        (-5)
    00061 #define GWEN_SOCKET_ERROR_INTERRUPTED    (-6)
    00062 #define GWEN_SOCKET_ERROR_UNSUPPORTED    (-7)
    00063 #define GWEN_SOCKET_ERROR_ABORTED        (-8)
    00064 #define GWEN_SOCKET_ERROR_BROKEN_PIPE    (-9)
    00065
    00071 typedef enum {
    00072   GWEN_SocketTypeTCP=1,
    00073   GWEN_SocketTypeUDP,
    00074   GWEN_SocketTypeRAW,
    00075   GWEN_SocketTypeUnix
    00076 } GWEN_SOCKETTYPE;
    00077
    00078
    00079 typedef struct GWEN_SOCKETSTRUCT GWEN_SOCKET;
    00080
    00081 typedef struct GWEN_SOCKETSETSTRUCT GWEN_SOCKETSET;
    00082
    00083
    00101 GWENHYWFAR_API GWEN_SOCKETSET *GWEN_SocketSet_new();
    00102 GWENHYWFAR_API void GWEN_SocketSet_free(GWEN_SOCKETSET *ssp);
    00103 GWENHYWFAR_API GWEN_ERRORCODE GWEN_SocketSet_Clear(GWEN_SOCKETSET *ssp);
    00113 GWENHYWFAR_API
    00114   GWEN_ERRORCODE GWEN_SocketSet_AddSocket(GWEN_SOCKETSET *ssp,
    00115                                           const GWEN_SOCKET *sp);
    00116 GWENHYWFAR_API
    00117   GWEN_ERRORCODE GWEN_SocketSet_RemoveSocket(GWEN_SOCKETSET *ssp,
    00118                                              const GWEN_SOCKET *sp);
    00119 GWENHYWFAR_API int GWEN_SocketSet_HasSocket(GWEN_SOCKETSET *ssp,
    00120                                             const GWEN_SOCKET *sp);
    00121 GWENHYWFAR_API int GWEN_SocketSet_GetSocketCount(GWEN_SOCKETSET *ssp);
    00122
    00124 /*end of group socketset */
    00139
    00143 GWENHYWFAR_API GWEN_SOCKET *GWEN_Socket_new(GWEN_SOCKETTYPE socketType);
    00144
    00148 GWENHYWFAR_API void GWEN_Socket_free(GWEN_SOCKET *sp);
    00149
    00154 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Open(GWEN_SOCKET *sp);
    00155
    00159 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Close(GWEN_SOCKET *sp);
    00168 GWENHYWFAR_API
    00169   GWEN_ERRORCODE GWEN_Socket_Connect(GWEN_SOCKET *sp,
    00170                                      const GWEN_INETADDRESS *addr);
    00171
    00182 GWENHYWFAR_API
    00183   GWEN_ERRORCODE GWEN_Socket_Connect_Wait(GWEN_SOCKET *sp,
    00184                                           const GWEN_INETADDRESS *addr,
    00185                                           int timeout);
    00186
    00187 GWENHYWFAR_API
    00188   GWEN_ERRORCODE GWEN_Socket_Bind(GWEN_SOCKET *sp,
    00189                                   const GWEN_INETADDRESS *addr);
    00190 GWENHYWFAR_API
    00191   GWEN_ERRORCODE GWEN_Socket_Listen(GWEN_SOCKET *sp, int backlog);
    00192
    00207 GWENHYWFAR_API
    00208   GWEN_ERRORCODE GWEN_Socket_Accept(GWEN_SOCKET *sp,
    00209                                     GWEN_INETADDRESS **addr,
    00210                                     GWEN_SOCKET **newsock);
    00211
    00212 GWENHYWFAR_API
    00213   GWEN_ERRORCODE GWEN_Socket_Accept_Wait(GWEN_SOCKET *sp,
    00214                                          GWEN_INETADDRESS **addr,
    00215                                          GWEN_SOCKET **newsock,
    00216                                          int timeout);
    00226
    00231 GWENHYWFAR_API GWEN_SOCKETTYPE GWEN_Socket_GetSocketType(GWEN_SOCKET *sp);
    00232
    00233
    00241 GWENHYWFAR_API
    00242   GWEN_ERRORCODE GWEN_Socket_GetPeerAddr(GWEN_SOCKET *sp,
    00243                                          GWEN_INETADDRESS **addr);
    00244
    00253 GWENHYWFAR_API
    00254   GWEN_ERRORCODE GWEN_Socket_Select(GWEN_SOCKETSET *rs,
    00255                                     GWEN_SOCKETSET *ws,
    00256                                     GWEN_SOCKETSET *xs,
    00257                                     int timeout);
    00258
    00264 GWENHYWFAR_API
    00265   GWEN_ERRORCODE GWEN_Socket_WaitForRead(GWEN_SOCKET *sp, int timeout);
    00266
    00272 GWENHYWFAR_API
    00273   GWEN_ERRORCODE GWEN_Socket_WaitForWrite(GWEN_SOCKET *sp, int timeout);
    00283
    00292 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Read(GWEN_SOCKET *sp,
    00293                                                char *buffer,
    00294                                                int *bsize);
    00295
    00296 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Read_Wait(GWEN_SOCKET *sp,
    00297                                                     char *buffer,
    00298                                                     int *bsize,
    00299                                                     int timeout,
    00300                                                     int force);
    00301
    00310 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Write(GWEN_SOCKET *sp,
    00311                                                 const char *buffer,
    00312                                                 int *bsize);
    00313
    00314 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_Write_Wait(GWEN_SOCKET *sp,
    00315                                                      const char *buffer,
    00316                                                      int *bsize,
    00317                                                      int timeout,
    00318                                                      int force);
    00319
    00332 GWENHYWFAR_API
    00333   GWEN_ERRORCODE GWEN_Socket_ReadFrom(GWEN_SOCKET *sp,
    00334                                       GWEN_INETADDRESS **addr,
    00335                                       char *buffer,
    00336                                       int *bsize);
    00346 GWENHYWFAR_API
    00347   GWEN_ERRORCODE GWEN_Socket_WriteTo(GWEN_SOCKET *sp,
    00348                                      const GWEN_INETADDRESS *addr,
    00349                                      const char *buffer,
    00350                                      int *bsize);
    00364 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_SetBlocking(GWEN_SOCKET *sp,
    00365                                                       int fl);
    00374 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_SetBroadcast(GWEN_SOCKET *sp,
    00375                                                        int fl);
    00376
    00385 GWENHYWFAR_API GWEN_ERRORCODE GWEN_Socket_GetSocketError(GWEN_SOCKET *sp);
    00386
    00395 GWENHYWFAR_API
    00396   GWEN_ERRORCODE GWEN_Socket_SetReuseAddress(GWEN_SOCKET *sp, int fl);
    00399 /* end of group socket */
    00402 /* end of group socketsandsets */
    00405 #ifdef __cplusplus
    00406 }
    00407 #endif
    00408
    00409 #endif /* GWEN_SOCKET_H */
    00410
    00411
    00412