Changeset 32:fd970caf83eb in vscpl


Ignore:
Timestamp:
12/15/22 18:11:45 (2 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Generic POSIX socket acceptor class.

Location:
src/hu/varadiistvan/scpl/io/_posix
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/hu/varadiistvan/scpl/io/_posix/LocalAcceptor.h

    r8 r32  
    3131//------------------------------------------------------------------------------
    3232
    33 #include "Acceptor.h"
     33#include "SocketAcceptor.h"
    3434
    3535#include "LocalSocket.h"
     
    4242
    4343/**
    44  * An acceptor that provides a LocalSocket for each accepted
    45  * connection.
     44 * An acceptor that provides a LocalSocket for each accepted connection
    4645 */
    47 class LocalAcceptor : public Acceptor
     46class LocalAcceptor : public SocketAcceptor<LocalSocket>
    4847{
    4948private:
    50     /**
    51      * Construct the acceptor.
    52      *
    53      * @param addressLength the length of the buffer for the peer
    54      * address. If 0, not buffer will be created.
    55      */
    56     LocalAcceptor(ServerSocket* socket);
    57 
    58 public:
    59     /**
    60      * Get the local socket accepted last. If no socket was accepted,
    61      * return 0. The local socket's waiter will be the given one
    62      * (which can be 0).
    63      */
    64     LocalSocket* getSocket(Waiter* waiter,
    65                            size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
    66                            size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
    67     /**
    68      * Get the local socket accepted last. If no socket was accepted,
    69      * return 0. The local socket's waiter will be the same as that of
    70      * the associated server socket.
    71      */
    72     LocalSocket* getSocket(size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
    73                            size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
    74 
     49    using SocketAcceptor<LocalSocket>::SocketAcceptor;
    7550
    7651    friend class LocalServerSocket;
    7752};
    78 
    79 //------------------------------------------------------------------------------
    80 // Inline definitions
    81 //------------------------------------------------------------------------------
    82 
    83 inline LocalAcceptor::LocalAcceptor(ServerSocket* socket) :
    84     Acceptor(socket)
    85 {
    86 }
    87 
    88 //------------------------------------------------------------------------------
    89 
    90 inline LocalSocket* LocalAcceptor::getSocket(Waiter* waiter,
    91                                              size_t readingCapacity,
    92                                              size_t writingCapacity)
    93 {
    94     if (acceptedFD<0) return 0;
    95 
    96     LocalSocket* socket = new LocalSocket(acceptedFD, waiter,
    97                                           readingCapacity, writingCapacity);
    98     connectionProcessed();
    99     return socket;
    100 }
    101 
    102 //------------------------------------------------------------------------------
    103 
    104 inline LocalSocket* LocalAcceptor::getSocket(size_t readingCapacity,
    105                                              size_t writingCapacity)
    106 {
    107     return getSocket(socket.getWaiter(), readingCapacity, writingCapacity);
    108 }
    10953
    11054//------------------------------------------------------------------------------
  • src/hu/varadiistvan/scpl/io/_posix/LocalSocket.h

    r8 r32  
    5252                size_t writingCapacity = DEFAULT_CAPACITY);
    5353
    54     friend class LocalAcceptor;
     54    friend class SocketAcceptor<LocalSocket>;
    5555};
    5656
  • src/hu/varadiistvan/scpl/io/_posix/Makefile.am

    r25 r32  
    1818        LocalClientSocket.cc    \
    1919        Acceptor.cc             \
     20        SocketAcceptor.h        \
    2021        ServerSocket.cc         \
    2122        LocalServerSocket.cc
     
    3637        LocalClientSocket.h     \
    3738        Acceptor.h              \
     39        SocketAcceptor.h        \
    3840        ServerSocket.h          \
    3941        LocalSocket.h           \
Note: See TracChangeset for help on using the changeset viewer.