OpendTect  6.6
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
Network::Socket Class Reference
Inheritance diagram for Network::Socket:
[legend]

Public Types

enum  ReadStatus { ReadOK , Timeout , ReadError }
 

Public Member Functions

 Socket (bool islocal, bool haveeventloop=true)
 
 Socket (QLocalSocket *, bool haveeventloop=true)
 
 Socket (QTcpSocket *, bool haveeventloop=true)
 
 ~Socket ()
 
void abort ()
 Just stops all pending operations. More...
 
od_int64 bytesAvailable () const
 
bool connectToHost (const Authority &, bool wait=true)
 
bool disconnectFromHost (bool wait=false)
 
uiString errMsg () const
 
bool isBad () const
 
bool isConnected () const
 
bool isLocal () const
 
QObject * qSocket ()
 
bool read (BufferString &) const
 
bool read (IOPar &) const
 
ReadStatus read (Network::RequestPacket &) const
 
ReadStatus readArray (void *, od_int64) const
 
bool readChar (char &) const
 
bool readDouble (double &) const
 
bool readDoubleArray (double *, od_int64) const
 
bool readFloat (float &) const
 
bool readFloatArray (float *, od_int64) const
 
bool readInt32 (od_int32 &) const
 
bool readInt32Array (od_int32 *, od_int64) const
 
bool readInt64 (od_int64 &) const
 
bool readInt64Array (od_int64 *, od_int64) const
 
bool readShort (short &) const
 
bool readShortArray (short *, od_int64) const
 
void setTimeout (int ms)
 
Threads::ThreadID thread () const
 
bool write (const IOPar &)
 
bool write (const Network::RequestPacket &, bool wait=false)
 
bool write (const OD::String &)
 
bool writeArray (const void *, od_int64, bool wait=false)
 
bool writeChar (char)
 
bool writeDouble (double)
 
bool writeDoubleArray (const double *, od_int64, bool wait=false)
 
bool writeFloat (float)
 
bool writeFloatArray (const float *, od_int64, bool wait=false)
 
bool writeInt32 (od_int32)
 
bool writeInt32Array (const od_int32 *, od_int64, bool wait=false)
 
bool writeInt64 (od_int64)
 
bool writeInt64Array (const od_int64 *, od_int64, bool wait=false)
 
bool writeShort (short)
 
bool writeShortArray (const short *, od_int64, bool wait=false)
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (const NotifierAccess &, const CallBack &, bool onlyifnew=false) const
 
bool attachCB (const NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false) const
 
void detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
virtual bool isCapsule () const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
void stopReceivingNotifications () const
 

Static Public Member Functions

static const char * sKeyLocalHost ()
 
- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 

Public Attributes

Notifier< Socketdisconnected
 usually remote host terminates. More...
 
Notifier< Socketerror
 
Notifier< SocketreadyRead
 

Private Member Functions

QString getSocketErrMsg () const
 
uiString noConnErrMsg () const
 
uiString readErrMsg () const
 
bool waitForConnected () const
 
bool waitForNewData () const
 
bool waitForWrite (bool all) const
 

Private Attributes

uiString errmsg_
 
Threads::Lock lock_
 
bool noeventloop_
 
bool ownssocket_
 
QLocalSocket * qlocalsocket_ = nullptr
 
QTcpSocket * qtcpsocket_ = nullptr
 
QTcpSocketCommsocketcomm_
 
const Threads::ThreadID thread_
 
int timeout_ = 30000
 

Detailed Description

Enables the connection and sending of binary and text data through a socket both with and without event-loops.

After construction, you need to connect to a host on a port. If you choose not to wait then (dis-)connecting only fails if it is already in progress.

Strings are transferred without trailing '\0', but with a leading integer for the size.

<>

Member Enumeration Documentation

◆ ReadStatus

Enumerator
ReadOK 
Timeout 
ReadError 

Constructor & Destructor Documentation

◆ Socket() [1/3]

Network::Socket::Socket ( bool  islocal,
bool  haveeventloop = true 
)

◆ Socket() [2/3]

Network::Socket::Socket ( QTcpSocket *  ,
bool  haveeventloop = true 
)
explicit

◆ Socket() [3/3]

Network::Socket::Socket ( QLocalSocket *  ,
bool  haveeventloop = true 
)
explicit

◆ ~Socket()

Network::Socket::~Socket ( )

Member Function Documentation

◆ abort()

void Network::Socket::abort ( )

Just stops all pending operations.

◆ bytesAvailable()

od_int64 Network::Socket::bytesAvailable ( ) const

◆ connectToHost()

bool Network::Socket::connectToHost ( const Authority ,
bool  wait = true 
)

◆ disconnectFromHost()

bool Network::Socket::disconnectFromHost ( bool  wait = false)

◆ errMsg()

uiString Network::Socket::errMsg ( ) const
inline

◆ getSocketErrMsg()

QString Network::Socket::getSocketErrMsg ( ) const
private

◆ isBad()

bool Network::Socket::isBad ( ) const

◆ isConnected()

bool Network::Socket::isConnected ( ) const

◆ isLocal()

bool Network::Socket::isLocal ( ) const
inline

◆ noConnErrMsg()

uiString Network::Socket::noConnErrMsg ( ) const
private

◆ qSocket()

QObject* Network::Socket::qSocket ( )

◆ read() [1/3]

bool Network::Socket::read ( BufferString ) const

◆ read() [2/3]

bool Network::Socket::read ( IOPar ) const

◆ read() [3/3]

ReadStatus Network::Socket::read ( Network::RequestPacket ) const

◆ readArray()

ReadStatus Network::Socket::readArray ( void *  ,
od_int64   
) const

◆ readChar()

bool Network::Socket::readChar ( char &  ) const

◆ readDouble()

bool Network::Socket::readDouble ( double &  ) const

◆ readDoubleArray()

bool Network::Socket::readDoubleArray ( double *  ,
od_int64   
) const

◆ readErrMsg()

uiString Network::Socket::readErrMsg ( ) const
private

◆ readFloat()

bool Network::Socket::readFloat ( float &  ) const

◆ readFloatArray()

bool Network::Socket::readFloatArray ( float *  ,
od_int64   
) const

◆ readInt32()

bool Network::Socket::readInt32 ( od_int32 &  ) const

◆ readInt32Array()

bool Network::Socket::readInt32Array ( od_int32 *  ,
od_int64   
) const

◆ readInt64()

bool Network::Socket::readInt64 ( od_int64 &  ) const

◆ readInt64Array()

bool Network::Socket::readInt64Array ( od_int64 *  ,
od_int64   
) const

◆ readShort()

bool Network::Socket::readShort ( short &  ) const

◆ readShortArray()

bool Network::Socket::readShortArray ( short *  ,
od_int64   
) const

◆ setTimeout()

void Network::Socket::setTimeout ( int  ms)
inline

◆ sKeyLocalHost()

static const char* Network::Socket::sKeyLocalHost ( )
inlinestatic

◆ thread()

Threads::ThreadID Network::Socket::thread ( ) const
inline

◆ waitForConnected()

bool Network::Socket::waitForConnected ( ) const
private
Note
Lock should be unlocked when calling

◆ waitForNewData()

bool Network::Socket::waitForNewData ( ) const
private
Note
Lock should be locked when calling

◆ waitForWrite()

bool Network::Socket::waitForWrite ( bool  all) const
private
Note
Lock should be locked when calling

◆ write() [1/3]

bool Network::Socket::write ( const IOPar )

◆ write() [2/3]

bool Network::Socket::write ( const Network::RequestPacket ,
bool  wait = false 
)

◆ write() [3/3]

bool Network::Socket::write ( const OD::String )

◆ writeArray()

bool Network::Socket::writeArray ( const void *  ,
od_int64  ,
bool  wait = false 
)

◆ writeChar()

bool Network::Socket::writeChar ( char  )

◆ writeDouble()

bool Network::Socket::writeDouble ( double  )

◆ writeDoubleArray()

bool Network::Socket::writeDoubleArray ( const double *  ,
od_int64  ,
bool  wait = false 
)

◆ writeFloat()

bool Network::Socket::writeFloat ( float  )

◆ writeFloatArray()

bool Network::Socket::writeFloatArray ( const float *  ,
od_int64  ,
bool  wait = false 
)

◆ writeInt32()

bool Network::Socket::writeInt32 ( od_int32  )

◆ writeInt32Array()

bool Network::Socket::writeInt32Array ( const od_int32 *  ,
od_int64  ,
bool  wait = false 
)

◆ writeInt64()

bool Network::Socket::writeInt64 ( od_int64  )

◆ writeInt64Array()

bool Network::Socket::writeInt64Array ( const od_int64 *  ,
od_int64  ,
bool  wait = false 
)

◆ writeShort()

bool Network::Socket::writeShort ( short  )

◆ writeShortArray()

bool Network::Socket::writeShortArray ( const short *  ,
od_int64  ,
bool  wait = false 
)

Member Data Documentation

◆ disconnected

Notifier<Socket> Network::Socket::disconnected

usually remote host terminates.

◆ errmsg_

uiString Network::Socket::errmsg_
mutableprivate

◆ error

Notifier<Socket> Network::Socket::error

◆ lock_

Threads::Lock Network::Socket::lock_
mutableprivate

◆ noeventloop_

bool Network::Socket::noeventloop_
private

◆ ownssocket_

bool Network::Socket::ownssocket_
private

◆ qlocalsocket_

QLocalSocket* Network::Socket::qlocalsocket_ = nullptr
private

◆ qtcpsocket_

QTcpSocket* Network::Socket::qtcpsocket_ = nullptr
private

◆ readyRead

Notifier<Socket> Network::Socket::readyRead

Note that object may or may not be locked, so you may not be able to read immediately

◆ socketcomm_

QTcpSocketComm* Network::Socket::socketcomm_
private

◆ thread_

const Threads::ThreadID Network::Socket::thread_
private

◆ timeout_

int Network::Socket::timeout_ = 30000
private

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022