private fork
Fork of GSwifiInterface by
Socket/UDPSocket.h@5:78943b3945b5, 2013-01-27 (annotated)
- Committer:
- gsfan
- Date:
- Sun Jan 27 14:31:19 2013 +0000
- Revision:
- 5:78943b3945b5
- Parent:
- 1:fb4494783863
- Child:
- 8:64184a968e3b
1st build
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 5:78943b3945b5 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
gsfan | 5:78943b3945b5 | 2 | * |
gsfan | 5:78943b3945b5 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
gsfan | 5:78943b3945b5 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
gsfan | 5:78943b3945b5 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
gsfan | 5:78943b3945b5 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
gsfan | 5:78943b3945b5 | 7 | * furnished to do so, subject to the following conditions: |
gsfan | 5:78943b3945b5 | 8 | * |
gsfan | 5:78943b3945b5 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
gsfan | 5:78943b3945b5 | 10 | * substantial portions of the Software. |
gsfan | 5:78943b3945b5 | 11 | * |
gsfan | 5:78943b3945b5 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
gsfan | 5:78943b3945b5 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
gsfan | 5:78943b3945b5 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
gsfan | 5:78943b3945b5 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gsfan | 5:78943b3945b5 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
gsfan | 5:78943b3945b5 | 17 | */ |
gsfan | 5:78943b3945b5 | 18 | /* Copyright (C) 2013 gsfan, MIT License |
gsfan | 5:78943b3945b5 | 19 | * port to the GainSpan Wi-FI module GS1011 |
gsfan | 5:78943b3945b5 | 20 | */ |
gsfan | 5:78943b3945b5 | 21 | |
gsfan | 5:78943b3945b5 | 22 | #ifndef UDPSOCKET_H |
gsfan | 5:78943b3945b5 | 23 | #define UDPSOCKET_H |
gsfan | 5:78943b3945b5 | 24 | |
gsfan | 5:78943b3945b5 | 25 | #include "Endpoint.h" |
gsfan | 5:78943b3945b5 | 26 | #include "Socket.h" |
gsfan | 5:78943b3945b5 | 27 | |
gsfan | 5:78943b3945b5 | 28 | #include <cstdint> |
gsfan | 5:78943b3945b5 | 29 | |
gsfan | 5:78943b3945b5 | 30 | /** |
gsfan | 5:78943b3945b5 | 31 | UDP Socket |
gsfan | 5:78943b3945b5 | 32 | */ |
gsfan | 5:78943b3945b5 | 33 | class UDPSocket: public Socket { |
gsfan | 5:78943b3945b5 | 34 | |
gsfan | 5:78943b3945b5 | 35 | public: |
gsfan | 5:78943b3945b5 | 36 | /** Instantiate an UDP Socket. |
gsfan | 5:78943b3945b5 | 37 | */ |
gsfan | 5:78943b3945b5 | 38 | UDPSocket(); |
gsfan | 5:78943b3945b5 | 39 | |
gsfan | 5:78943b3945b5 | 40 | /** Init the UDP Client Socket without binding it to any specific port |
gsfan | 5:78943b3945b5 | 41 | \return 0 on success, -1 on failure. |
gsfan | 5:78943b3945b5 | 42 | */ |
gsfan | 5:78943b3945b5 | 43 | int init(void); |
gsfan | 5:78943b3945b5 | 44 | |
gsfan | 5:78943b3945b5 | 45 | /** Bind a UDP Server Socket to a specific port |
gsfan | 5:78943b3945b5 | 46 | \param port The port to listen for incoming connections on |
gsfan | 5:78943b3945b5 | 47 | \return 0 on success, -1 on failure. |
gsfan | 5:78943b3945b5 | 48 | */ |
gsfan | 5:78943b3945b5 | 49 | int bind(int port = -1); |
gsfan | 5:78943b3945b5 | 50 | |
gsfan | 5:78943b3945b5 | 51 | /** Send a packet to a remote endpoint |
gsfan | 5:78943b3945b5 | 52 | \param remote The remote endpoint |
gsfan | 5:78943b3945b5 | 53 | \param packet The packet to be sent |
gsfan | 5:78943b3945b5 | 54 | \param length The length of the packet to be sent |
gsfan | 5:78943b3945b5 | 55 | \return the number of written bytes on success (>=0) or -1 on failure |
gsfan | 5:78943b3945b5 | 56 | */ |
gsfan | 5:78943b3945b5 | 57 | int sendTo(Endpoint &remote, char *packet, int length); |
gsfan | 5:78943b3945b5 | 58 | |
gsfan | 5:78943b3945b5 | 59 | /** Receive a packet from a remote endpoint |
gsfan | 5:78943b3945b5 | 60 | \param remote The remote endpoint |
gsfan | 5:78943b3945b5 | 61 | \param buffer The buffer for storing the incoming packet data. If a packet |
gsfan | 5:78943b3945b5 | 62 | is too long to fit in the supplied buffer, excess bytes are discarded |
gsfan | 5:78943b3945b5 | 63 | \param length The length of the buffer |
gsfan | 5:78943b3945b5 | 64 | \return the number of received bytes on success (>=0) or -1 on failure |
gsfan | 5:78943b3945b5 | 65 | */ |
gsfan | 5:78943b3945b5 | 66 | int receiveFrom(Endpoint &remote, char *buffer, int length); |
gsfan | 5:78943b3945b5 | 67 | |
gsfan | 5:78943b3945b5 | 68 | private: |
gsfan | 5:78943b3945b5 | 69 | bool endpoint_connected; |
gsfan | 5:78943b3945b5 | 70 | int sendPacket (Endpoint &ep, const char *buf, int len); |
gsfan | 5:78943b3945b5 | 71 | |
gsfan | 5:78943b3945b5 | 72 | }; |
gsfan | 5:78943b3945b5 | 73 | |
gsfan | 5:78943b3945b5 | 74 | #include "def.h" |
gsfan | 5:78943b3945b5 | 75 | |
gsfan | 5:78943b3945b5 | 76 | #endif |