FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stream.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 2013 Frediano Ziglio
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _freetds_stream_h_
21 #define _freetds_stream_h_
22 
23 #ifndef _tds_h_
24 #error Include tds.h first
25 #endif
26 
27 #include <freetds/pushvis.h>
28 
30 typedef struct tds_input_stream {
35  int (*read)(struct tds_input_stream *stream, void *ptr, size_t len);
36 } TDSINSTREAM;
37 
39 typedef struct tds_output_stream {
41  int (*write)(struct tds_output_stream *stream, size_t len);
50  char *buffer;
51  size_t buf_len;
52 } TDSOUTSTREAM;
53 
55 TDSRET tds_convert_stream(TDSSOCKET * tds, TDSICONV * char_conv, TDS_ICONV_DIRECTION direction,
56  TDSINSTREAM * istream, TDSOUTSTREAM *ostream);
58 TDSRET tds_copy_stream(TDSSOCKET * tds, TDSINSTREAM * istream, TDSOUTSTREAM * ostream);
59 
60 /* Additional streams */
61 
63 typedef struct tds_datain_stream {
64  TDSINSTREAM stream;
65  size_t wire_size;
66  TDSSOCKET *tds;
68 
69 void tds_datain_stream_init(TDSDATAINSTREAM * stream, TDSSOCKET * tds, size_t wire_size);
70 
72 typedef struct tds_dataout_stream {
73  TDSOUTSTREAM stream;
74  TDSSOCKET *tds;
75  size_t written;
77 
79 
81 typedef struct tds_staticin_stream {
82  TDSINSTREAM stream;
83  const char *buffer;
84  size_t buf_left;
86 
87 void tds_staticin_stream_init(TDSSTATICINSTREAM * stream, const void *ptr, size_t len);
88 
92 typedef struct tds_staticout_stream {
93  TDSOUTSTREAM stream;
95 
96 void tds_staticout_stream_init(TDSSTATICOUTSTREAM * stream, void *ptr, size_t len);
97 
99 typedef struct tds_dynamic_stream {
100  TDSOUTSTREAM stream;
102  void **buf;
104  size_t allocated;
106  size_t size;
108 
109 TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM * stream, void **ptr, size_t allocated);
110 
111 #include <freetds/popvis.h>
112 
113 #endif
114 
void ** buf
where is stored the pointer
Definition: stream.h:102
size_t wire_size
bytes still to read
Definition: stream.h:65
Information for a server connection.
Definition: tds.h:1168
void tds_staticin_stream_init(TDSSTATICINSTREAM *stream, const void *ptr, size_t len)
Initialize an input stream for read from a static allocated buffer.
Definition: stream.c:285
TDSRET tds_copy_stream(TDSSOCKET *tds, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream to another.
Definition: stream.c:163
output stream to write data to a dynamic buffer
Definition: stream.h:99
void tds_staticout_stream_init(TDSSTATICOUTSTREAM *stream, void *ptr, size_t len)
Initialize an output stream for write into a static allocated buffer.
Definition: stream.c:312
int(* read)(struct tds_input_stream *stream, void *ptr, size_t len)
read some data Return 0 if end of stream Return <0 if error (actually not defined) ...
Definition: stream.h:35
void tds_dataout_stream_init(TDSDATAOUTSTREAM *stream, TDSSOCKET *tds)
Initialize a data output stream.
Definition: stream.c:243
Definition: iconv.h:91
define a stream of data used for input
Definition: stream.h:30
output stream to write data to a static buffer.
Definition: stream.h:92
void tds_datain_stream_init(TDSDATAINSTREAM *stream, TDSSOCKET *tds, size_t wire_size)
Initialize a data input stream.
Definition: stream.c:203
size_t size
size of data inside buffer
Definition: stream.h:106
output stream to write data to tds protocol
Definition: stream.h:72
size_t allocated
currently allocated buffer
Definition: stream.h:104
input stream to read data from a static buffer
Definition: stream.h:81
char * buffer
write buffer.
Definition: stream.h:50
TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM *stream, void **ptr, size_t allocated)
Initialize a dynamic output stream.
Definition: stream.c:353
TDSRET tds_convert_stream(TDSSOCKET *tds, TDSICONV *char_conv, TDS_ICONV_DIRECTION direction, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream converting characters.
Definition: stream.c:71
define a stream of data used for output
Definition: stream.h:39
input stream to read data from tds protocol
Definition: stream.h:63
int(* write)(struct tds_output_stream *stream, size_t len)
write len bytes from buffer, return <0 if error or len
Definition: stream.h:41