socket.h

Go to the documentation of this file.
00001 // socket.h
00002 //
00003 /****************************************************************************
00004    liblscp - LinuxSampler Control Protocol API
00005    Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00020 
00021 *****************************************************************************/
00022 
00023 #ifndef __LSCP_SOCKET_H
00024 #define __LSCP_SOCKET_H
00025 
00026 #include "lscp/thread.h"
00027 
00028 #if defined(WIN32)
00029 #include <winsock.h>
00030 #else
00031 #include <unistd.h>
00032 #include <sys/socket.h>
00033 #include <netinet/in.h>
00034 #include <netinet/tcp.h>
00035 #include <arpa/inet.h>
00036 #include <netdb.h>
00037 #endif
00038 
00039 #if defined(__cplusplus)
00040 extern "C" {
00041 #endif
00042 
00043 //-------------------------------------------------------------------------
00044 // Sockets.
00045 
00046 #if defined(WIN32)
00047 typedef SOCKET lscp_socket_t;
00048 #else
00049 typedef int lscp_socket_t;
00050 #define INVALID_SOCKET  -1
00051 #define SOCKET_ERROR    -1
00052 #define closesocket(s)  close(s)
00053 #endif
00054 
00055 #define LSCP_BUFSIZ     1024
00056 
00057 void lscp_socket_perror (const char *pszPrefix);
00058 void lscp_socket_herror (const char *pszPrefix);
00059 
00060 void lscp_socket_getopts (const char *pszPrefix, lscp_socket_t sock);
00061 void lscp_socket_trace   (const char *pszPrefix, struct sockaddr_in *pAddr, const char *pchBuffer, int cchBuffer);
00062 
00063 
00064 //-------------------------------------------------------------------------
00065 // Threaded socket agent struct helpers.
00066 
00067 typedef struct _lscp_socket_agent_t {
00068 
00069     lscp_socket_t       sock;
00070     struct sockaddr_in  addr;
00071     lscp_thread_t      *pThread;
00072     int                 iState;
00073 
00074 } lscp_socket_agent_t;
00075 
00076 void          lscp_socket_agent_init  (lscp_socket_agent_t *pAgent, lscp_socket_t sock, struct sockaddr_in *pAddr, int cAddr);
00077 lscp_status_t lscp_socket_agent_start (lscp_socket_agent_t *pAgent, lscp_thread_proc_t pfnProc, void *pvData, int iDetach);
00078 lscp_status_t lscp_socket_agent_join  (lscp_socket_agent_t *pAgent);
00079 lscp_status_t lscp_socket_agent_free  (lscp_socket_agent_t *pAgent);
00080 
00081 #if defined(__cplusplus)
00082 }
00083 #endif
00084 
00085 
00086 #endif // __LSCP_SOCKET_H
00087 
00088 // end of socket.h

Generated on Wed Aug 24 17:21:28 2005 for liblscp by  doxygen 1.4.4