1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
29
#ifndef __CSSOCKET_H__
30
#define __CSSOCKET_H__
36
#include "CSException.h"
45
class CSSocket : public CSRefObject {
49
virtual ~CSSocket() { }
51
CSOutputStream *getOutputStream();
53
CSInputStream *getInputStream();
55
virtual void formatAddress(size_t size, char *address) = 0;
60
virtual void publish(char *service, int default_port) = 0;
63
* Accept a connection from a listening socket:
65
virtual void open(CSSocket *listener) = 0;
68
* Connect to a listening socket.
70
virtual void open(char *address, int default_port) = 0;
75
virtual void close() { }
78
* Read at least one byte from the socket.
79
* This function returns 0 on EOF.
80
* If the function returns at least
81
* one byte, then you must call the function
82
* again, there may be more data available.
84
* Note: Errors on the socket do not cause
87
virtual size_t read(void *data, size_t size) = 0;
91
* Otherwize it returns a character value >= 0
92
* Just like read, error on the socket do
93
* not throw an exception.
95
virtual int read() = 0;
98
* Look at the next character in the file without
99
* taking from the input.
101
virtual int peek() = 0;
104
* Write the given number of bytes.
105
* Throws IOException if an error occurs.
107
virtual void write(const void *data, size_t size) = 0;
110
* Write a character to the file.
112
virtual void write(char ch) = 0;
115
* Flush the data written.
117
virtual void flush() = 0;
119
static CSSocket *newSocket();
121
friend class SCSocket;
126
#define CS_SOCKET_ADDRESS_SIZE 300
128
class SCSocket : public CSSocket {
130
SCSocket(): CSSocket(), iHandle(-1), iHost(NULL), iService(NULL), iPort(0) { }
132
virtual ~SCSocket() {
136
virtual void formatAddress(size_t size, char *address);
138
virtual void publish(char *service, int default_port);
140
virtual void open(CSSocket *listener);
142
virtual void open(char *address, int default_port);
144
virtual void close();
146
virtual size_t read(void *data, size_t size);
152
virtual void write(const void *data, size_t size);
154
virtual void write(char ch);
156
virtual void flush();
159
void throwError(const char *func, const char *file, int line, char *address, int err);
160
void throwError(const char *func, const char *file, int line, int err);
161
void setInternalOptions();