Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

nsnet.h

Go to the documentation of this file.
00001 /*
00002 NeuroServer
00003  
00004 A collection of programs to translate between EEG data and TCP network
00005 messages. This is a part of the OpenEEG project, see http://openeeg.sf.net
00006 for details.
00007     
00008 Copyright (C) 2003, 2004 Rudi Cilibrasi (cilibrar@ofb.net)
00009      
00010 This library is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU Lesser General Public
00012 License as published by the Free Software Foundation; either
00013 version 2.1 of the License, or (at your option) any later version.
00014          
00015 This library is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 Lesser General Public License for more details.
00019              
00020 You should have received a copy of the GNU Lesser General Public
00021 License along with this library; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00023 */
00024                 
00025 
00026 #ifndef __NSNET_H
00027 #define __NSNET_H
00028 #include <nsutil.h>
00029 
00030 #define CHUNKSIZE 256
00031 
00032 #define DEFAULTPORT 8336
00033 #define DEFAULTHOST "localhost"
00034 #define MAXCLIENTS 16
00035 
00036 //#if defined(__MINGW32__) || defined(__CYGWIN__)
00037 //#include <winsock2.h>
00038 //#define sock_t SOCKET
00039 //#include <sys/types.h>
00040 //#define sock_t int
00041 //#define rsockaddr_t struct sockaddr_in
00042 //#define rsockaddr_t SOCKADDR_IN
00043 //#define hostent_t LPHOSTENT
00044 //#else
00045 #include <sys/types.h>
00046 #include <errno.h>
00047 #include <sys/socket.h>
00048 #include <netinet/in.h>
00049 #include <netdb.h>
00050 #include <arpa/inet.h>
00051 typedef struct hostent *hostent_t;
00052 #define sock_t int
00053 #define rsockaddr_t struct sockaddr_in
00054 //#endif
00055 
00056 struct InputBuffer {
00057         int read_cnt;
00058         int isEOF;
00059         char *read_ptr;
00060         char read_buf[MAXLEN];
00061 };
00062 
00063 struct OutputBuffer {
00064         int write_cnt;
00065         char write_buf[MAXLEN];
00066 };
00067 
00068 sock_t rsocket(void);
00069 int readline(sock_t fd, char *vptr, size_t maxlen, struct InputBuffer *ib);
00070 const char *stringifyErrorCode(int code);
00071 int rbindAll(sock_t sock_fd);
00072 int writeBytes(sock_t con, const char *buf, int size, struct OutputBuffer *ob);
00073 int writeString(sock_t con, const char *buf, struct OutputBuffer *ob);
00074 int rconnectName(sock_t sock_fd, const char *hostname, unsigned short portno);
00075 int rinitNetworking(void);
00076 sock_t raccept(sock_t sock_fd);
00077 void setblocking(sock_t sock_fd);
00078 void setnonblocking(sock_t sock_fd);
00079 void rshutdown(sock_t fd);
00081 int getResponseCode(sock_t sock_fd, struct InputBuffer *);
00082 int getOK(sock_t sock_fd, struct InputBuffer *);
00083 int rrecv(sock_t fd, char *read_buf, size_t count);
00084 void initInputBuffer(struct InputBuffer *ib);
00085 void initOutputBuffer(struct OutputBuffer *ob);
00086 int isEOF(sock_t con, const struct InputBuffer *ib);
00087 int inputBufferEmpty(const struct InputBuffer *ib);
00088 int my_read(sock_t fd, char *ptr, size_t maxlen, struct InputBuffer *);
00089 size_t readlinebuf(void **vptrptr, struct InputBuffer *);
00090 size_t writen(sock_t fd, const void *vptr, size_t len, struct OutputBuffer *ob);
00091 size_t readn(sock_t fd, void *vptr, size_t len, struct InputBuffer *ib);
00092 int rselect(sock_t max_fd, fd_set *read, fd_set *write, fd_set *err);
00093 int rselect_timed(sock_t max_fd, fd_set *toread, fd_set *towrite, 
00094         fd_set *toerr, struct timeval *tv);
00096 int findFdIndex(sock_t fd);
00097 #endif

Generated on Tue Feb 8 00:05:16 2005 for Neuroserver by doxygen 1.3.3