victor qiu / Mbed OS SimpleNTP

Fork of SimpleNTP by Akinori Hashimoto

Committer:
victorqiu2
Date:
Tue Aug 01 01:22:01 2017 +0000
Revision:
2:68ae27667d82
A

Who changed what in which revision?

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