Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Socket.h
1#ifndef STK_SOCKET_H
2#define STK_SOCKET_H
3
4#include "Stk.h"
5
6#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
7
8 #include <sys/socket.h>
9 #include <sys/types.h>
10 #include <arpa/inet.h>
11 #include <netdb.h>
12 #include <unistd.h>
13 #include <fcntl.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
16
17#elif defined(__OS_WINDOWS__)
18
19 #include <winsock.h>
20
21#endif
22
23namespace stk {
24
25/***************************************************/
36/***************************************************/
37
38class Socket : public Stk
39{
40 public:
41
42 enum ProtocolType {
43 PROTO_TCP,
44 PROTO_UDP
45 };
46
49
51 virtual ~Socket();
52
54 static void close( int socket );
55
57 int id( void ) const { return soket_; };
58
60 int port( void ) const { return port_; };
61
63 static bool isValid( int socket ) { return socket != -1; };
64
66 static void setBlocking( int socket, bool enable );
67
69 virtual int writeBuffer(const void *buffer, long bufferSize, int flags = 0) = 0;
70
72 virtual int readBuffer(void *buffer, long bufferSize, int flags = 0) = 0;
73
75 static int writeBuffer(int socket, const void *buffer, long bufferSize, int flags );
76
78 static int readBuffer(int socket, void *buffer, long bufferSize, int flags );
79
80 protected:
81
82 int soket_;
83 int port_;
84
85};
86
87} // stk namespace
88
89#endif
STK internet socket abstract base class.
Definition Socket.h:39
static void setBlocking(int socket, bool enable)
If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default...
int port(void) const
Return the socket port number.
Definition Socket.h:60
Socket()
Class constructor.
static bool isValid(int socket)
Returns true if the socket descriptor is valid.
Definition Socket.h:63
static int readBuffer(int socket, void *buffer, long bufferSize, int flags)
Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs.
virtual int writeBuffer(const void *buffer, long bufferSize, int flags=0)=0
Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occu...
int id(void) const
Return the socket descriptor.
Definition Socket.h:57
static void close(int socket)
Close the socket.
virtual ~Socket()
Class destructor.
static int writeBuffer(int socket, const void *buffer, long bufferSize, int flags)
Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs...
virtual int readBuffer(void *buffer, long bufferSize, int flags=0)=0
Read an input buffer, up to length bufferSize. Returns the number of bytes read or -1 if an error occ...
STK base class.
Definition Stk.h:136
The STK namespace.
Definition ADSR.h:6

The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.