Overview
Comment: | Add cfw_stream_read_line().
This also adds a caching infrastructure to cfw_stream. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2cee5ea2d537c745497b002efec05889 |
User & Date: | js on 2012-09-30 01:01:37 |
Other Links: | manifest | tags |
Context
2012-09-30
| ||
01:02 | Add cfw_stream_write_line(). check-in: 168ba16eda user: js tags: trunk | |
01:01 | Add cfw_stream_read_line(). check-in: 2cee5ea2d5 user: js tags: trunk | |
00:59 | Fix cfw_strndup() and add cfw_strnlen(). check-in: 3247812f3b user: js tags: trunk | |
Changes
Modified src/file.c from [6570f4dc53] to [222c0e621d].
︙ | |||
140 141 142 143 144 145 146 | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | - - + + - + | ctor(void *ptr, va_list args) { CFWFile *file = ptr; const char *path = va_arg(args, const char*); const char *mode = va_arg(args, const char*); int flags; |
︙ |
Modified src/stream.c from [5dca9bcc2f] to [7f07dd8ac4].
︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <stdlib.h> #include <string.h> #include "stream.h" #define BUFFER_SIZE 4096 static bool ctor(void *ptr, va_list args) { CFWStream *stream = ptr; stream->ops = NULL; stream->cache = NULL; stream->cache_len = 0; return true; } static void dtor(void *ptr) { cfw_stream_close(ptr); } ssize_t cfw_stream_read(void *ptr, void *buf, size_t len) { CFWStream *stream = ptr; ssize_t ret; if (stream == NULL || stream->ops == NULL) return -1; if (stream->cache == NULL) { |
︙ | |||
79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | + + + | bool cfw_stream_eof(void *ptr) { CFWStream *stream = ptr; if (stream == NULL || stream->ops == NULL) return true; if (stream->cache != NULL) return false; return stream->ops->eof(stream); } void cfw_stream_close(void *ptr) { |
︙ |
Modified src/stream.h from [80dfac9647] to [768e2d2979].
︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | + + + + | #ifndef __COREFW_STREAM_H__ #define __COREFW_STREAM_H__ #include <unistd.h> #include "class.h" #include "object.h" #include "string.h" struct cfw_stream_ops { ssize_t (*read)(void*, void*, size_t); bool (*write)(void*, const void*, size_t); bool (*eof)(void*); void (*close)(void*); }; typedef struct CFWStream { CFWObject obj; struct cfw_stream_ops *ops; char *cache; size_t cache_len; } CFWStream; extern CFWClass *cfw_stream; extern ssize_t cfw_stream_read(void*, void*, size_t); extern CFWString* cfw_stream_read_line(void*); extern bool cfw_stream_write(void*, const void*, size_t); extern bool cfw_stream_write_string(void*, const char*); extern bool cfw_stream_eof(void*); extern void cfw_stream_close(void*); #endif |
Modified src/tcpsocket.c from [8af7b73d7d] to [f4d3eaafb5].
︙ | |||
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | + + - + | }; static bool ctor(void *ptr, va_list args) { CFWTCPSocket *sock = ptr; cfw_stream->ctor(ptr, args); sock->fd = -1; sock->stream.ops = &stream_ops; sock->eof = false; return true; } static void dtor(void *ptr) { |
︙ |