mbed socket API

Dependents:   EthernetInterface EthernetInterface_RSF EthernetInterface EthernetInterface ... more

Deprecated

This is an mbed 2 sockets library. For mbed 5, network sockets have been revised to better support additional network stacks and thread safety here.

Committer:
emilmont
Date:
Wed Aug 01 13:02:32 2012 +0000
Revision:
11:3d83c348fb8b
Parent:
8:9cf9c2d45264
Child:
16:2d471deff212
[Socket library] Remove redundant UDPPacket class. Use centralized socket destructor. Add is_connected check.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 5:300e7ad2dc1d 1 /* Copyright (C) 2012 mbed.org, MIT License
emilmont 5:300e7ad2dc1d 2 *
emilmont 5:300e7ad2dc1d 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
emilmont 5:300e7ad2dc1d 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
emilmont 5:300e7ad2dc1d 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
emilmont 5:300e7ad2dc1d 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
emilmont 5:300e7ad2dc1d 7 * furnished to do so, subject to the following conditions:
emilmont 5:300e7ad2dc1d 8 *
emilmont 5:300e7ad2dc1d 9 * The above copyright notice and this permission notice shall be included in all copies or
emilmont 5:300e7ad2dc1d 10 * substantial portions of the Software.
emilmont 5:300e7ad2dc1d 11 *
emilmont 5:300e7ad2dc1d 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
emilmont 5:300e7ad2dc1d 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
emilmont 5:300e7ad2dc1d 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
emilmont 5:300e7ad2dc1d 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 5:300e7ad2dc1d 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emilmont 5:300e7ad2dc1d 17 */
emilmont 5:300e7ad2dc1d 18 #ifndef ENDPOINT_H
emilmont 5:300e7ad2dc1d 19 #define ENDPOINT_H
emilmont 5:300e7ad2dc1d 20
emilmont 11:3d83c348fb8b 21 class UDPSocket;
emilmont 11:3d83c348fb8b 22
emilmont 8:9cf9c2d45264 23 /**
emilmont 8:9cf9c2d45264 24 IP Endpoint (address, port)
emilmont 8:9cf9c2d45264 25 */
emilmont 5:300e7ad2dc1d 26 class Endpoint {
emilmont 11:3d83c348fb8b 27 friend class UDPSocket;
emilmont 5:300e7ad2dc1d 28
emilmont 5:300e7ad2dc1d 29 public:
emilmont 8:9cf9c2d45264 30 /** IP Endpoint (address, port)
emilmont 8:9cf9c2d45264 31 */
emilmont 5:300e7ad2dc1d 32 Endpoint(void);
emilmont 5:300e7ad2dc1d 33
emilmont 5:300e7ad2dc1d 34 ~Endpoint(void);
emilmont 5:300e7ad2dc1d 35
emilmont 8:9cf9c2d45264 36 /** Reset the address of this endpoint
emilmont 8:9cf9c2d45264 37 */
emilmont 5:300e7ad2dc1d 38 void reset_address(void);
emilmont 8:9cf9c2d45264 39
emilmont 8:9cf9c2d45264 40 /** Set the address of this endpoint
emilmont 8:9cf9c2d45264 41 \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS).
emilmont 8:9cf9c2d45264 42 \param port The endpoint port
emilmont 8:9cf9c2d45264 43 \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS).
emilmont 8:9cf9c2d45264 44 */
emilmont 5:300e7ad2dc1d 45 int set_address(const char* host, const int port);
emilmont 5:300e7ad2dc1d 46
emilmont 8:9cf9c2d45264 47 /** Get the IP address of this endpoint
emilmont 8:9cf9c2d45264 48 \return The IP address of this endpoint.
emilmont 8:9cf9c2d45264 49 */
emilmont 5:300e7ad2dc1d 50 char* get_address(void);
emilmont 8:9cf9c2d45264 51
emilmont 8:9cf9c2d45264 52 /** Get the port of this endpoint
emilmont 8:9cf9c2d45264 53 \return The port of this endpoint
emilmont 8:9cf9c2d45264 54 */
emilmont 8:9cf9c2d45264 55 int get_port(void);
emilmont 5:300e7ad2dc1d 56
emilmont 5:300e7ad2dc1d 57 protected:
emilmont 5:300e7ad2dc1d 58 char _ipAddress[16];
emilmont 5:300e7ad2dc1d 59 struct sockaddr_in _remoteHost;
emilmont 5:300e7ad2dc1d 60
emilmont 5:300e7ad2dc1d 61 };
emilmont 5:300e7ad2dc1d 62
emilmont 5:300e7ad2dc1d 63 #endif