2017-02-22 15:55:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An interface in front of various streams
|
|
|
|
*/
|
|
|
|
struct Stream {
|
|
|
|
/**
|
|
|
|
* A generic socket descriptor
|
|
|
|
*/
|
|
|
|
void* socket_descriptor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads from the stream
|
|
|
|
* @param stream the stream
|
|
|
|
* @param buffer where to put the results
|
|
|
|
* @param bytes_read how many bytes were read
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
2017-02-23 20:16:04 +00:00
|
|
|
int (*read)(struct Stream* stream, unsigned char** buffer, size_t* bytes_read);
|
2017-02-22 15:55:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes to a stream
|
|
|
|
* @param stream the stream
|
|
|
|
* @param buffer what to write
|
|
|
|
* @param how much to write
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
2017-02-23 20:16:04 +00:00
|
|
|
int (*write)(struct Stream* stream, const unsigned char* buffer, size_t buffer_size);
|
2017-02-22 15:55:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes a stream
|
|
|
|
* @param stream the stream
|
|
|
|
* @returns true(1) on success, otherwise false(0)
|
|
|
|
*/
|
|
|
|
int (*close)(struct Stream* stream);
|
|
|
|
};
|