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