ap

Dependencies:   DnsQuery

Dependents:   WizFi310_TCP_Echo_Server_Example

Fork of NetworkSocketAPI by NetworkSocketAPI

Committer:
Christopher Haster
Date:
Tue Apr 05 09:16:47 2016 -0500
Revision:
77:b66a6984ed2d
Parent:
75:dea0cdb42241
Child:
78:0914f9b9b24b
Integrated interfaces as arguments to sockets

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 72:6a8b52ee83ed 1 /* Copyright (C) 2012 mbed.org, MIT License
Christopher Haster 72:6a8b52ee83ed 2 *
Christopher Haster 72:6a8b52ee83ed 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Christopher Haster 72:6a8b52ee83ed 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Christopher Haster 72:6a8b52ee83ed 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Christopher Haster 72:6a8b52ee83ed 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Christopher Haster 72:6a8b52ee83ed 7 * furnished to do so, subject to the following conditions:
Christopher Haster 72:6a8b52ee83ed 8 *
Christopher Haster 72:6a8b52ee83ed 9 * The above copyright notice and this permission notice shall be included in all copies or
Christopher Haster 72:6a8b52ee83ed 10 * substantial portions of the Software.
Christopher Haster 72:6a8b52ee83ed 11 *
Christopher Haster 72:6a8b52ee83ed 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Christopher Haster 72:6a8b52ee83ed 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Christopher Haster 72:6a8b52ee83ed 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Christopher Haster 72:6a8b52ee83ed 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Christopher Haster 72:6a8b52ee83ed 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Christopher Haster 72:6a8b52ee83ed 17 */
Christopher Haster 72:6a8b52ee83ed 18
Christopher Haster 72:6a8b52ee83ed 19 #ifndef UDPSOCKET_H
Christopher Haster 72:6a8b52ee83ed 20 #define UDPSOCKET_H
Christopher Haster 72:6a8b52ee83ed 21
Christopher Haster 72:6a8b52ee83ed 22 #include "Socket.h"
Christopher Haster 77:b66a6984ed2d 23 #include "NetworkInterface.h"
Christopher Haster 72:6a8b52ee83ed 24
Christopher Haster 72:6a8b52ee83ed 25 /**
Christopher Haster 72:6a8b52ee83ed 26 UDP Socket
Christopher Haster 72:6a8b52ee83ed 27 */
Christopher Haster 72:6a8b52ee83ed 28 class UDPSocket : public Socket {
Christopher Haster 72:6a8b52ee83ed 29 public:
Christopher Haster 72:6a8b52ee83ed 30 /** UDPSocket lifetime
Christopher Haster 72:6a8b52ee83ed 31 */
Christopher Haster 77:b66a6984ed2d 32 UDPSocket(NetworkInterface *iface);
Christopher Haster 72:6a8b52ee83ed 33 ~UDPSocket();
Christopher Haster 72:6a8b52ee83ed 34
Christopher Haster 72:6a8b52ee83ed 35 /** Bind a UDP Server Socket to a specific port
Christopher Haster 72:6a8b52ee83ed 36 \param port The port to listen for incoming connections on
Christopher Haster 72:6a8b52ee83ed 37 \return 0 on success, negative on failure.
Christopher Haster 72:6a8b52ee83ed 38 */
Christopher Haster 72:6a8b52ee83ed 39 int bind(int port);
Christopher Haster 75:dea0cdb42241 40
Christopher Haster 72:6a8b52ee83ed 41 /** Send a packet to a remote endpoint
Christopher Haster 75:dea0cdb42241 42 \param address The remote SocketAddress
Christopher Haster 72:6a8b52ee83ed 43 \param data The packet to be sent
Christopher Haster 72:6a8b52ee83ed 44 \param size The length of the packet to be sent
Christopher Haster 74:ef2470ca328b 45 \return the number of written bytes on success, negative on failure
Christopher Haster 72:6a8b52ee83ed 46 */
Christopher Haster 75:dea0cdb42241 47 int sendto(SocketAddress address, const void *data, unsigned size);
Christopher Haster 75:dea0cdb42241 48
Christopher Haster 72:6a8b52ee83ed 49 /** Receive a packet from a remote endpoint
Christopher Haster 75:dea0cdb42241 50 \param address Destination for the remote SocketAddress or null
Christopher Haster 72:6a8b52ee83ed 51 \param buffer The buffer for storing the incoming packet data
Christopher Haster 72:6a8b52ee83ed 52 If a packet is too long to fit in the supplied buffer,
Christopher Haster 72:6a8b52ee83ed 53 excess bytes are discarded
Christopher Haster 72:6a8b52ee83ed 54 \param size The length of the buffer
Christopher Haster 72:6a8b52ee83ed 55 \return the number of received bytes on success, negative on failure
Christopher Haster 72:6a8b52ee83ed 56 */
Christopher Haster 75:dea0cdb42241 57 int recvfrom(SocketAddress *address, void *buffer, unsigned size);
Christopher Haster 73:968f7b32278f 58
Christopher Haster 73:968f7b32278f 59 /** Register a callback on when send is ready
Christopher Haster 73:968f7b32278f 60 \param callback Function to call when send will succeed, may be called in
Christopher Haster 73:968f7b32278f 61 interrupt context.
Christopher Haster 73:968f7b32278f 62 */
Christopher Haster 73:968f7b32278f 63 void attach_send(FuncPtr<void()> callback);
Christopher Haster 73:968f7b32278f 64
Christopher Haster 73:968f7b32278f 65 /** Register a callback on when recv is ready
Christopher Haster 73:968f7b32278f 66 \param callback Function to call when recv will succeed, may be called in
Christopher Haster 73:968f7b32278f 67 interrupt context.
Christopher Haster 73:968f7b32278f 68 */
Christopher Haster 73:968f7b32278f 69 void attach_recv(FuncPtr<void()> callback);
Christopher Haster 72:6a8b52ee83ed 70 };
Christopher Haster 72:6a8b52ee83ed 71
Christopher Haster 72:6a8b52ee83ed 72 #endif