Back to index

im-sdk  12.3.91
Public Types | Public Member Functions | Private Member Functions | Private Attributes
IMSocket Class Reference

#include <IMUtil.hh>

List of all members.

Public Types

enum  LISTEN_STATUS { CLOSED, OPEN, ERROR }

Public Member Functions

bool listen ()
IMSocketTransaccept ()
int get_fd ()
enum LISTEN_STATUS get_status () const
 IMSocket (int fd)
 IMSocket (int fd, int trans_type)
 ~IMSocket ()

Private Member Functions

enum LISTEN_STATUS bool do_listen ()
 IMSocket (const IMSocket &a)
IMSocketoperator= (const IMSocket &a)

Private Attributes

int fd
int trans_type

Detailed Description

Definition at line 112 of file IMUtil.hh.


Member Enumeration Documentation

Enumerator:
CLOSED 
OPEN 
ERROR 

Definition at line 115 of file IMUtil.hh.

                       {
           CLOSED,
           OPEN,
           ERROR
    };

Constructor & Destructor Documentation

IMSocket::IMSocket ( const IMSocket a) [private]
IMSocket::IMSocket ( int  fd)

Definition at line 754 of file IMUtil.cpp.

IMSocket::IMSocket ( int  fd,
int  trans_type 
)

Definition at line 767 of file IMUtil.cpp.

  : fd(x_fd), status(CLOSED), trans_type(x_trans)
{
}

Definition at line 760 of file IMUtil.cpp.

{
    if (status == OPEN) {
       close(fd);
    }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 716 of file IMUtil.cpp.

{
    int st;
#ifdef HAVE_SOCKADDR_STORAGE
    struct sockaddr_storage ss;
#else
    struct sockaddr ss;
#endif
    struct sockaddr *psa = (struct sockaddr*) &ss;
    socklen_t fromlen;

    if (status == ERROR) return NULL;

    do {
       fromlen = sizeof(ss);
       st = ::accept(fd, psa, &fromlen);
       if (st != -1) {
#ifdef HAVE_TLS
            return IMTLS::get_instance()->create_trans(st, trans_type);
#else
           return new IMSocketTrans(st);
#endif
       }
    } while (errno == EINTR);

    status = ERROR;
    LOG_ERROR("Could not accept.\n");

    return NULL;
}

Here is the caller graph for this function:

bool IMSocket::do_listen ( ) [abstract, private]

Definition at line 692 of file IMUtil.cpp.

{
    if (::listen(fd, 5) < 0) {
       LOG_ERROR("Fail to listen:%d", fd);
       close(fd);
       status = ERROR;
       return false;
    }

    status = OPEN;

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 748 of file IMUtil.cpp.

{
    if (status == OPEN) return fd;
    return -1;
}

Here is the caller graph for this function:

enum LISTEN_STATUS IMSocket::get_status ( ) const [inline]

Definition at line 140 of file IMUtil.hh.

    { return status; }

Here is the caller graph for this function:

bool IMSocket::listen ( )

Definition at line 707 of file IMUtil.cpp.

{
    if (status == ERROR) return false;
    if (status == OPEN) return true;

    return do_listen();
}

Here is the call graph for this function:

Here is the caller graph for this function:

IMSocket& IMSocket::operator= ( const IMSocket a) [private]

Member Data Documentation

int IMSocket::fd [private]

Definition at line 121 of file IMUtil.hh.

int IMSocket::trans_type [private]

Definition at line 122 of file IMUtil.hh.


The documentation for this class was generated from the following files: