liblscp 1.0.0

socket.h
Go to the documentation of this file.
1// socket.h
2//
3/****************************************************************************
4 liblscp - LinuxSampler Control Protocol API
5 Copyright (C) 2004-2021, rncbc aka Rui Nuno Capela. All rights reserved.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21*****************************************************************************/
22
23#ifndef __LSCP_SOCKET_H
24#define __LSCP_SOCKET_H
25
26#include "lscp/thread.h"
27
28#if defined(WIN32)
29#include <winsock.h>
30#else
31#include <unistd.h>
32#include <sys/socket.h>
33#include <netinet/in.h>
34#include <netinet/tcp.h>
35#include <arpa/inet.h>
36#include <netdb.h>
37#endif
38
39#if defined(__cplusplus)
40 extern "C" {
41#endif
42
43//-------------------------------------------------------------------------
44// Sockets.
45
46#if defined(WIN32)
47 typedef SOCKET lscp_socket_t;
48 typedef int socklen_t;
49#else
50 typedef int lscp_socket_t;
51#define INVALID_SOCKET -1
52#define SOCKET_ERROR -1
53#define closesocket(s) close(s)
54#endif
55
56#define LSCP_BUFSIZ 1024
57
58 void lscp_socket_perror (const char *pszPrefix);
59 void lscp_socket_herror (const char *pszPrefix);
60
61 void lscp_socket_getopts (const char *pszPrefix, lscp_socket_t sock);
62 void lscp_socket_trace (const char *pszPrefix, struct sockaddr_in *pAddr, const char *pchBuffer, int cchBuffer);
63
64
65//-------------------------------------------------------------------------
66// Threaded socket agent struct helpers.
67
68 typedef struct _lscp_socket_agent_t {
69
70 lscp_socket_t sock;
71 struct sockaddr_in addr;
72 lscp_thread_t *pThread;
73 int iState;
74
75} lscp_socket_agent_t;
76
77 void lscp_socket_agent_init (lscp_socket_agent_t *pAgent, lscp_socket_t sock, struct sockaddr_in *pAddr, int cAddr);
78 lscp_status_t lscp_socket_agent_start (lscp_socket_agent_t *pAgent, lscp_thread_proc_t pfnProc, void *pvData, int iDetach);
79 lscp_status_t lscp_socket_agent_join (lscp_socket_agent_t *pAgent);
80 lscp_status_t lscp_socket_agent_free (lscp_socket_agent_t *pAgent);
81
82#if defined(__cplusplus)
83}
84#endif
85
86
87#endif // __LSCP_SOCKET_H
88
89// end of socket.h
lscp_socket_getopts
void lscp_socket_getopts(const char *pszPrefix, lscp_socket_t sock)
Definition: socket.c:153
lscp_socket_agent_t
struct _lscp_socket_agent_t lscp_socket_agent_t
lscp_socket_agent_init
void lscp_socket_agent_init(lscp_socket_agent_t *pAgent, lscp_socket_t sock, struct sockaddr_in *pAddr, int cAddr)
Definition: socket.c:198
lscp_socket_t
int lscp_socket_t
Definition: socket.h:50
lscp_socket_agent_start
lscp_status_t lscp_socket_agent_start(lscp_socket_agent_t *pAgent, lscp_thread_proc_t pfnProc, void *pvData, int iDetach)
Definition: socket.c:211
lscp_socket_herror
void lscp_socket_herror(const char *pszPrefix)
Definition: socket.c:119
lscp_socket_agent_free
lscp_status_t lscp_socket_agent_free(lscp_socket_agent_t *pAgent)
Definition: socket.c:236
lscp_socket_trace
void lscp_socket_trace(const char *pszPrefix, struct sockaddr_in *pAddr, const char *pchBuffer, int cchBuffer)
Definition: socket.c:170
lscp_socket_agent_join
lscp_status_t lscp_socket_agent_join(lscp_socket_agent_t *pAgent)
Definition: socket.c:225
lscp_socket_perror
void lscp_socket_perror(const char *pszPrefix)
Definition: socket.c:114
_lscp_socket_agent_t
Definition: socket.h:68
_lscp_socket_agent_t::sock
lscp_socket_t sock
Definition: socket.h:70
_lscp_socket_agent_t::pThread
lscp_thread_t * pThread
Definition: socket.h:72
_lscp_socket_agent_t::addr
struct sockaddr_in addr
Definition: socket.h:71
_lscp_socket_agent_t::iState
int iState
Definition: socket.h:73
_lscp_thread_t
Definition: thread.c:29
thread.h
lscp_thread_proc_t
void(* lscp_thread_proc_t)(void *pvData)
Definition: thread.h:101
lscp_status_t
enum _lscp_status_t lscp_status_t