Skip to content

Commit

Permalink
Added SCPITransport::IsConnected() for error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed May 25, 2020
1 parent bb56e70 commit e04e0a0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scopehal/SCPILxiTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ SCPILxiTransport::~SCPILxiTransport()
delete[] m_staging_buf;
}

bool SCPILxiTransport::IsConnected()
{
return (m_device != LXI_ERROR);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual transport code

Expand Down
1 change: 1 addition & 0 deletions scopehal/SCPILxiTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SCPILxiTransport : public SCPITransport
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
virtual bool IsConnected();

TRANSPORT_INITPROC(SCPILxiTransport)

Expand Down
7 changes: 7 additions & 0 deletions scopehal/SCPISocketTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ SCPISocketTransport::SCPISocketTransport(string args)

if(!m_socket.Connect(m_hostname, m_port))
{
m_socket.Close();
LogError("Couldn't connect to socket\n");
return;
}
if(!m_socket.DisableNagle())
{
m_socket.Close();
LogError("Couldn't disable Nagle\n");
return;
}
Expand All @@ -75,6 +77,11 @@ SCPISocketTransport::~SCPISocketTransport()
{
}

bool SCPISocketTransport::IsConnected()
{
return m_socket.IsValid();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual transport code

Expand Down
1 change: 1 addition & 0 deletions scopehal/SCPISocketTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SCPISocketTransport : public SCPITransport
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
virtual bool IsConnected();

TRANSPORT_INITPROC(SCPISocketTransport)

Expand Down
1 change: 1 addition & 0 deletions scopehal/SCPITransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SCPITransport
virtual void SendRawData(size_t len, const unsigned char* buf) =0;

virtual bool IsCommandBatchingSupported() =0;
virtual bool IsConnected() =0;

public:
typedef SCPITransport* (*CreateProcType)(std::string args);
Expand Down
7 changes: 7 additions & 0 deletions scopehal/VICPSocketTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ VICPSocketTransport::VICPSocketTransport(string args)

if(!m_socket.Connect(m_hostname, m_port))
{
m_socket.Close();
LogError("Couldn't connect to socket\n");
return;
}
if(!m_socket.DisableNagle())
{
m_socket.Close();
LogError("Couldn't disable Nagle\n");
return;
}
Expand All @@ -75,6 +77,11 @@ VICPSocketTransport::~VICPSocketTransport()
{
}

bool VICPSocketTransport::IsConnected()
{
return m_socket.IsValid();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual transport code

Expand Down
1 change: 1 addition & 0 deletions scopehal/VICPSocketTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class VICPSocketTransport : public SCPITransport
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
virtual bool IsConnected();

//VICP constant helpers
enum HEADER_OPS
Expand Down

0 comments on commit e04e0a0

Please sign in to comment.