1
/* Copyright (c) 2007 SNAP Innovation GmbH
3
* BLOB Streaming 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
* Paul McCullagh (H&G2JCtL)
28
#ifndef __CSSOCKET_H__
29
#define __CSSOCKET_H__
35
#include "CSException.h"
44
class CSSocket : public CSRefObject {
48
virtual ~CSSocket() { }
50
CSOutputStream *getOutputStream();
52
CSInputStream *getInputStream();
54
virtual void formatAddress(size_t size, char *address) = 0;
59
virtual void publish(char *service, int default_port) = 0;
62
* Accept a connection from a listening socket:
64
virtual void open(CSSocket *listener) = 0;
67
* Connect to a listening socket.
69
virtual void open(char *address, int default_port) = 0;
74
virtual void close() { }
77
* Read at least one byte from the socket.
78
* This function returns 0 on EOF.
79
* If the function returns at least
80
* one byte, then you must call the function
81
* again, there may be more data available.
83
* Note: Errors on the socket do not cause
86
virtual size_t read(void *data, size_t size) = 0;
90
* Otherwize it returns a character value >= 0
91
* Just like read, error on the socket do
92
* not throw an exception.
94
virtual int read() = 0;
97
* Look at the next character in the file without
98
* taking from the input.
100
virtual int peek() = 0;
103
* Write the given number of bytes.
104
* Throws IOException if an error occurs.
106
virtual void write(const void *data, size_t size) = 0;
109
* Write a character to the file.
111
virtual void write(char ch) = 0;
114
* Flush the data written.
116
virtual void flush() = 0;
118
static CSSocket *newSocket();
120
friend class SCSocket;
125
#define CS_SOCKET_ADDRESS_SIZE 300
127
class SCSocket : public CSSocket {
129
SCSocket(): CSSocket(), iHandle(-1), iHost(NULL), iService(NULL), iPort(0) { }
131
virtual ~SCSocket() {
135
virtual void formatAddress(size_t size, char *address);
137
virtual void publish(char *service, int default_port);
139
virtual void open(CSSocket *listener);
141
virtual void open(char *address, int default_port);
143
virtual void close();
145
virtual size_t read(void *data, size_t size);
151
virtual void write(const void *data, size_t size);
153
virtual void write(char ch);
155
virtual void flush();
158
void throwError(const char *func, const char *file, int line, char *address, int err);
159
void throwError(const char *func, const char *file, int line, int err);
160
void setInternalOptions();