modified by ohneta

Dependents:   HelloESP8266Interface_mine

Fork of NetworkSocketAPI by NetworkSocketAPI

SocketInterface.h

Committer:
bridadan
Date:
2015-05-19
Revision:
2:ce08986b18b5
Parent:
1:291a9d61e58a
Child:
7:b147c08301be

File content as of revision 2:ce08986b18b5:

/* SocketInterface Base Class
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef SOCKETINTERFACE_H
#define SOCKETINTERFACE_H

/** SocketInterface class.
 *   This is a common interface that is shared between all sockets that connect
 *   using the NetworkInterface.
 */
class SocketInterface {

public:
    /**
     *    This enum defines the possible socket protocol families.
     */
    enum ProtocolFamily {
        AF_INET,    /**< IPv4 */
        AF_INET6,   /**< IPV6 */
        AF_UNIX     /**< Local socket (using a file) */
    };
    
    /**
     *    This enum defines the possible socket types.
     */
    enum SockType {
        SOCK_STREAM,    /**< Stream socket, generally used for TCP */
        SOCK_DGRAM,     /**< Datagram socket, generally used for UDP */
        SOCK_SEQPACKET, /**< Reliable sequenced packet service */
        SOCK_RAW        /**< Raw protocols atop the network layer */
    };

    /**
     *    Configure the socket's protocol and type.
     *
     *    @param protocol The protocol to use.
     *    @param type The type of socket to use.
     */
    virtual int config(ProtocolFamily protocol, SockType type) = 0;
    
    /** 
     *    Set blocking or non-blocking mode of the socket and a timeout on
     *    blocking socket operations.
     *    
     *    @param blocking true for blocking mode, false for non-blocking mode.
     *    @param timeout timeout in ms [Default: (1500)ms].
     */
    virtual void setBlocking(bool blocking, unsigned int timeout=1500) = 0;
    
    /*
        "options" functions here? Not familiar with this, need to discuss
    */
    
    /**
     *    Close the socket
     */
    virtual void close();

};

#endif