A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers buffer.hpp Source File

buffer.hpp

00001 /**
00002  * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice, this
00009  *    list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00015  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00016  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00017  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00018  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00019  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00020  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00021  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00023  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 
00026 #ifndef _NETWORK_BUFFER_HPP_
00027 #define _NETWORK_BUFFER_HPP_
00028 
00029 #include <stdlib.h>
00030 #include <string>
00031 #include <cstring>
00032 
00033 namespace network
00034 {
00035     class Buffer
00036     {
00037         // Members
00038         protected:
00039             void *_memory;
00040             
00041             size_t _size;
00042             size_t _length;
00043         
00044         // Methods  
00045         public:
00046             Buffer();
00047             explicit Buffer(const Buffer &other);
00048             explicit Buffer(const size_t size);
00049             explicit Buffer(const std::string &other);
00050         
00051             ~Buffer();
00052             
00053             int read(void *data, size_t max_length, size_t offset = 0);
00054             int write(const void *data, size_t length, size_t offset = 0);
00055             int flush();
00056             
00057             void *data(size_t offset = 0);
00058             
00059             void length(size_t length);
00060             size_t length();
00061             
00062             size_t size();
00063             size_t free();
00064             
00065             Buffer &operator=(const Buffer &other);
00066             Buffer &operator=(const std::string &message);
00067        
00068        protected:
00069             int _memory_allocate(size_t size);
00070             void _memory_free();
00071             
00072     };
00073 
00074 } // namespace network
00075 
00076 #endif // _NETWORK_UDP_SOCKET_HPP_