# nettransport.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: nettransport.h,v $
    00003                              -------------------
    00004     cvs         : $Id: nettransport.h,v 1.12 2005/03/26 06:39:25 aquamaniac Exp $
    00005     begin       : Sat Jan 24 2004
    00006     copyright   : (C) 2004 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
    00028 #ifndef GWEN_NETTRANSPORT_H
    00029 #define GWEN_NETTRANSPORT_H
    00030
    00031 #include <gwenhywfar/gwenhywfarapi.h>
    00032 #ifdef __cplusplus
    00033 extern "C" {
    00034 #endif
    00035 typedef struct GWEN_NETTRANSPORT GWEN_NETTRANSPORT;
    00036 #ifdef __cplusplus
    00037 }
    00038 #endif
    00039
    00040 #include <gwenhywfar/types.h>
    00041 #include <gwenhywfar/inetaddr.h>
    00042 #include <gwenhywfar/inetsocket.h>
    00043 #include <gwenhywfar/misc.h>
    00044 #include <gwenhywfar/inherit.h>
    00045
    00046 #ifdef __cplusplus
    00047 extern "C" {
    00048 #endif
    00049
    00050 typedef enum {
    00051   GWEN_NetTransportWorkResult_NoChange=0,
    00052   GWEN_NetTransportWorkResult_Change,
    00053   GWEN_NetTransportWorkResult_Error
    00054 } GWEN_NETTRANSPORT_WORKRESULT;
    00055
    00056
    00057 GWEN_LIST_FUNCTION_LIB_DEFS(GWEN_NETTRANSPORT, GWEN_NetTransport, GWENHYWFAR_API)
    00058 GWEN_INHERIT_FUNCTION_LIB_DEFS(GWEN_NETTRANSPORT, GWENHYWFAR_API)
    00059 /* No trailing semicolon here because this is a macro call */
    00060
    00061
    00073
    00074
    00075
    00080 #define GWEN_NETTRANSPORT_FLAGS_PASSIVE        0x0001
    00081 #define GWEN_NETTRANSPORT_FLAGS_EOF_IN         0x0002
    00082
    00083 #define GWEN_NETTRANSPORT_FLAGS_EOF_OUT        0x0004
    00084 #define GWEN_NETTRANSPORT_FLAGS_RESTARTABLE    0x0008
    00085 #define GWEN_NETTRANSPORT_FLAGS_WAS_LCONNECTED 0x0010
    00086 #define GWEN_NETTRANSPORT_FLAGS_WENT_DOWN      0x0020
    00087
    00093 typedef enum {
    00095   GWEN_NetTransportResultOk=0,
    00097   GWEN_NetTransportResultError,
    00102   GWEN_NetTransportResultWantRead,
    00107   GWEN_NetTransportResultWantWrite,
    00112   GWEN_NetTransportResultAborted
    00113 } GWEN_NETTRANSPORT_RESULT;
    00114
    00115
    00119 typedef enum {
    00121   GWEN_NetTransportStatusUnconnected=0,
    00123   GWEN_NetTransportStatusPConnecting,
    00125   GWEN_NetTransportStatusPConnected,
    00127   GWEN_NetTransportStatusLConnecting,
    00129   GWEN_NetTransportStatusLConnected,
    00131   GWEN_NetTransportStatusLDisconnecting,
    00133   GWEN_NetTransportStatusLDisconnected,
    00135   GWEN_NetTransportStatusPDisconnecting,
    00137   GWEN_NetTransportStatusPDisconnected,
    00139   GWEN_NetTransportStatusListening,
    00141   GWEN_NetTransportStatusDisabled
    00142 } GWEN_NETTRANSPORT_STATUS;
    00143
    00144
    00154 typedef GWEN_NETTRANSPORT_RESULT
    00155 (*GWEN_NETTRANSPORT_STARTCONNECT)(GWEN_NETTRANSPORT *tr);
    00156
    00157
    00163 typedef GWEN_NETTRANSPORT_RESULT
    00164   (*GWEN_NETTRANSPORT_STARTACCEPT)(GWEN_NETTRANSPORT *tr);
    00165
    00171 typedef GWEN_NETTRANSPORT_RESULT
    00172   (*GWEN_NETTRANSPORT_STARTDISCONNECT)(GWEN_NETTRANSPORT *tr);
    00173
    00181 typedef GWEN_NETTRANSPORT_RESULT
    00182   (*GWEN_NETTRANSPORT_READ)(GWEN_NETTRANSPORT *tr,
    00183                             char *buffer,
    00184                             int *bsize);
    00185
    00193 typedef GWEN_NETTRANSPORT_RESULT
    00194   (*GWEN_NETTRANSPORT_WRITE)(GWEN_NETTRANSPORT *tr,
    00195                              const char *buffer,
    00196                              int *bsize);
    00197
    00206 typedef int
    00207   (*GWEN_NETTRANSPORT_ADDSOCKETS)(GWEN_NETTRANSPORT *tr,
    00208                                   GWEN_SOCKETSET *sset,
    00209                                   int forReading);
    00210
    00214 typedef GWEN_NETTRANSPORT_WORKRESULT
    00215   (*GWEN_NETTRANSPORT_WORK)(GWEN_NETTRANSPORT *tr);
    00216
    00227 GWENHYWFAR_API
    00228 GWEN_NETTRANSPORT *GWEN_NetTransport_new();
    00229 void GWEN_NetTransport_free(GWEN_NETTRANSPORT *tr);
    00242 GWENHYWFAR_API
    00243 GWEN_NETTRANSPORT_RESULT
    00244   GWEN_NetTransport_StartConnect(GWEN_NETTRANSPORT *tr);
    00245
    00251 GWENHYWFAR_API
    00252 GWEN_NETTRANSPORT_RESULT
    00253   GWEN_NetTransport_StartAccept(GWEN_NETTRANSPORT *tr);
    00254
    00260 GWENHYWFAR_API
    00261 GWEN_NETTRANSPORT_RESULT
    00262   GWEN_NetTransport_StartDisconnect(GWEN_NETTRANSPORT *tr);
    00263
    00268 GWENHYWFAR_API
    00269 GWEN_NETTRANSPORT *GWEN_NetTransport_GetNextIncoming(GWEN_NETTRANSPORT *tr);
    00285 GWENHYWFAR_API
    00286 GWEN_NETTRANSPORT_RESULT
    00287   GWEN_NetTransport_Read(GWEN_NETTRANSPORT *tr,
    00288                          char *buffer,
    00289                          int *bsize);
    00290
    00298 GWENHYWFAR_API
    00299 GWEN_NETTRANSPORT_RESULT
    00300   GWEN_NetTransport_Write(GWEN_NETTRANSPORT *tr,
    00301                           const char *buffer,
    00302                           int *bsize);
    00319 GWENHYWFAR_API
    00320 int GWEN_NetTransport_AddSockets(GWEN_NETTRANSPORT *tr,
    00321                                  GWEN_SOCKETSET *sset,
    00322                                  int forReading);
    00323
    00327 GWENHYWFAR_API
    00328 GWEN_NETTRANSPORT_WORKRESULT GWEN_NetTransport_Work(GWEN_NETTRANSPORT *tr);
    00336 GWENHYWFAR_API
    00337 GWEN_NETTRANSPORT_STATUS
    00338   GWEN_NetTransport_GetStatus(const GWEN_NETTRANSPORT *tr);
    00339
    00340 GWENHYWFAR_API
    00341 void GWEN_NetTransport_SetStatus(GWEN_NETTRANSPORT *tr,
    00342                                  GWEN_NETTRANSPORT_STATUS st);
    00343
    00344 GWENHYWFAR_API
    00345 GWEN_TYPE_UINT32
    00346   GWEN_NetTransport_GetFlags(const GWEN_NETTRANSPORT *tr);
    00347
    00348 GWENHYWFAR_API
    00349 void GWEN_NetTransport_SetFlags(GWEN_NETTRANSPORT *tr,
    00350                                 GWEN_TYPE_UINT32 flags);
    00351 GWENHYWFAR_API
    00352 void GWEN_NetTransport_AddFlags(GWEN_NETTRANSPORT *tr,
    00353                                 GWEN_TYPE_UINT32 flags);
    00354 GWENHYWFAR_API
    00355 void GWEN_NetTransport_DelFlags(GWEN_NETTRANSPORT *tr,
    00356                                 GWEN_TYPE_UINT32 flags);
    00357
    00358 GWENHYWFAR_API
    00359 const GWEN_INETADDRESS*
    00360   GWEN_NetTransport_GetLocalAddr(const GWEN_NETTRANSPORT *tr);
    00361
    00362 GWENHYWFAR_API
    00363 void GWEN_NetTransport_SetLocalAddr(GWEN_NETTRANSPORT *tr,
    00364                                     const GWEN_INETADDRESS *addr);
    00365
    00366 GWENHYWFAR_API
    00367 const GWEN_INETADDRESS*
    00368   GWEN_NetTransport_GetPeerAddr(const GWEN_NETTRANSPORT *tr);
    00369
    00370 GWENHYWFAR_API
    00371 void GWEN_NetTransport_SetPeerAddr(GWEN_NETTRANSPORT *tr,
    00372                                    const GWEN_INETADDRESS *addr);
    00373
    00374 GWENHYWFAR_API
    00375 const char *GWEN_NetTransport_StatusName(GWEN_NETTRANSPORT_STATUS st);
    00376
    00377 GWENHYWFAR_API
    00378 const char *GWEN_NetTransport_ResultName(GWEN_NETTRANSPORT_RESULT res);
    00379
    00380 GWENHYWFAR_API
    00381 void GWEN_NetTransport_MarkActivity(GWEN_NETTRANSPORT *tr);
    00382
    00383 GWENHYWFAR_API
    00384 double GWEN_NetTransport_GetIdleTime(const GWEN_NETTRANSPORT *tr);
    00385
    00386 GWENHYWFAR_API
    00387 GWEN_TYPE_UINT32 GWEN_NetTransport_GetBackLog(const GWEN_NETTRANSPORT *tr);
    00388
    00389 GWENHYWFAR_API
    00390 void GWEN_NetTransport_SetBackLog(GWEN_NETTRANSPORT *tr, GWEN_TYPE_UINT32 i);
    00391
    00392 GWENHYWFAR_API
    00393 GWEN_TYPE_UINT32
    00394   GWEN_NetTransport_GetIncomingCount(const GWEN_NETTRANSPORT *tr);
    00395
    00403 GWENHYWFAR_API
    00404 void GWEN_NetTransport_AddNextIncoming(GWEN_NETTRANSPORT *tr,
    00405                                        GWEN_NETTRANSPORT *newTr);
    00414 GWENHYWFAR_API
    00415 void
    00416   GWEN_NetTransport_SetStartConnectFn(GWEN_NETTRANSPORT *tr,
    00417                                       GWEN_NETTRANSPORT_STARTCONNECT fn);
    00418
    00419 GWENHYWFAR_API
    00420 void
    00421   GWEN_NetTransport_SetStartAcceptFn(GWEN_NETTRANSPORT *tr,
    00422                                      GWEN_NETTRANSPORT_STARTACCEPT fn);
    00423
    00424 GWENHYWFAR_API
    00425 void
    00426   GWEN_NetTransport_SetStartDisconnectFn(GWEN_NETTRANSPORT *tr,
    00427                                          GWEN_NETTRANSPORT_STARTDISCONNECT fn);
    00428
    00429
    00430 GWENHYWFAR_API
    00431 void GWEN_NetTransport_SetReadFn(GWEN_NETTRANSPORT *tr,
    00432                                  GWEN_NETTRANSPORT_READ fn);
    00433
    00434 GWENHYWFAR_API
    00435 void GWEN_NetTransport_SetWriteFn(GWEN_NETTRANSPORT *tr,
    00436                                   GWEN_NETTRANSPORT_WRITE fn);
    00437
    00438 GWENHYWFAR_API
    00439 void GWEN_NetTransport_SetAddSocketsFn(GWEN_NETTRANSPORT *tr,
    00440                                        GWEN_NETTRANSPORT_ADDSOCKETS fn);
    00441
    00442 GWENHYWFAR_API
    00443 void GWEN_NetTransport_SetWorkFn(GWEN_NETTRANSPORT *tr,
    00444                                  GWEN_NETTRANSPORT_WORK fn);
    00445
    00448  /* defgroup */
    00449
    00450 #ifdef __cplusplus
    00451 }
    00452 #endif
    00453
    00454 #endif /* GWEN_NETTRANSPORT_H */
    00455