liblscp 0.5.6

socket.h

Go to the documentation of this file.
00001 // socket.h
00002 //
00003 /****************************************************************************
00004    liblscp - LinuxSampler Control Protocol API
00005    Copyright (C) 2004-2007, 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 General Public License along
00018    with this program; if not, write to the Free Software Foundation, Inc.,
00019    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 typedef int socklen_t;
00049 #else
00050 typedef int lscp_socket_t;
00051 #define INVALID_SOCKET  -1
00052 #define SOCKET_ERROR    -1
00053 #define closesocket(s)  close(s)
00054 #endif
00055 
00056 #define LSCP_BUFSIZ     1024
00057 
00058 void lscp_socket_perror (const char *pszPrefix);
00059 void lscp_socket_herror (const char *pszPrefix);
00060 
00061 void lscp_socket_getopts (const char *pszPrefix, lscp_socket_t sock);
00062 void lscp_socket_trace   (const char *pszPrefix, struct sockaddr_in *pAddr, const char *pchBuffer, int cchBuffer);
00063 
00064 
00065 //-------------------------------------------------------------------------
00066 // Threaded socket agent struct helpers.
00067 
00068 typedef struct _lscp_socket_agent_t {
00069 
00070     lscp_socket_t       sock;
00071     struct sockaddr_in  addr;
00072     lscp_thread_t      *pThread;
00073     int                 iState;
00074 
00075 } lscp_socket_agent_t;
00076 
00077 void          lscp_socket_agent_init  (lscp_socket_agent_t *pAgent, lscp_socket_t sock, struct sockaddr_in *pAddr, int cAddr);
00078 lscp_status_t lscp_socket_agent_start (lscp_socket_agent_t *pAgent, lscp_thread_proc_t pfnProc, void *pvData, int iDetach);
00079 lscp_status_t lscp_socket_agent_join  (lscp_socket_agent_t *pAgent);
00080 lscp_status_t lscp_socket_agent_free  (lscp_socket_agent_t *pAgent);
00081 
00082 #if defined(__cplusplus)
00083 }
00084 #endif
00085 
00086 
00087 #endif // __LSCP_SOCKET_H
00088 
00089 // end of socket.h