Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AH501B
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
spe
ds
AH501B
Commits
9f422918
Commit
9f422918
authored
3 years ago
by
Roberto Borghes
Browse files
Options
Downloads
Patches
Plain Diff
Delete ClientSocket.cpp
parent
0a2c7f67
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ClientSocket.cpp
+0
-186
0 additions, 186 deletions
ClientSocket.cpp
with
0 additions
and
186 deletions
ClientSocket.cpp
deleted
100755 → 0
+
0
−
186
View file @
0a2c7f67
//============================================================
//
// file: ClientSocket.cpp
//
// description: From an article in "Linux gazette" by Rob Tougher
// Implementation of the ClientSocket class.
// And modified later.
//
// project : TANGO Device Server.
//
// $Author: pascal_verdier $
//
// $Revision: 1.1.1.1 $
// $Log: ClientSocket.cpp,v $
// Revision 1.1.1.1 2007/01/12 10:07:43 pascal_verdier
// Initial Revision
//
//
// copyleft : European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// (c) - Software Engineering Group - ESRF
//=============================================================================
#include
"ClientSocket.h"
#include
"SocketException.h"
//#include <iostream>
//#include <string>
#include
<sstream>
//#include <tango.h>
using
namespace
std
;
//------------------------------------------------------------
/**
* ClientSocket constructor
*/
//------------------------------------------------------------
ClientSocket
::
ClientSocket
(
std
::
string
host
,
int
port
)
{
if
(
!
SocketAccess
::
create
())
{
throw
SocketException
(
"Cannot create client socket."
);
}
if
(
!
SocketAccess
::
connect
(
host
,
port
))
{
/*TangoSys_MemStream tms;
tms << "Cannot connect to " << host << ":" << port;
throw SocketException (tms.str());*/
stringstream
ss
;
ss
<<
"Cannot connect to "
<<
host
<<
":"
<<
port
;
throw
SocketException
(
ss
.
str
());
}
}
//------------------------------------------------------------
/**
* ClientSocket operator overload
*/
//------------------------------------------------------------
const
ClientSocket
&
ClientSocket
::
operator
<<
(
const
std
::
string
&
s
)
const
{
if
(
!
SocketAccess
::
send
(
s
))
{
throw
SocketException
(
"Write Socket Failed."
);
}
return
*
this
;
}
//------------------------------------------------------------
/**
* ClientSocket operator overload
*/
//------------------------------------------------------------
const
ClientSocket
&
ClientSocket
::
operator
>>
(
std
::
string
&
s
)
const
{
if
(
SocketAccess
::
recv
(
s
)
==
0
)
{
throw
SocketException
(
"Read Socket Failed."
);
}
return
*
this
;
}
//------------------------------------------------------------
/**
* ClientSocket set non blocking state
*/
//------------------------------------------------------------
void
ClientSocket
::
set_non_blocking
(
const
bool
b
)
{
SocketAccess
::
set_non_blocking
(
b
);
}
//------------------------------------------------------------
/**
* ClientSocket read line (until '\n')
*/
//------------------------------------------------------------
int
ClientSocket
::
recv
(
char
*
s
)
{
int
aux
=
SocketAccess
::
recv
(
s
);
if
(
aux
<=
0
)
{
throw
SocketException
(
"Read Socket Failed."
);
}
return
aux
;
}
//------------------------------------------------------------
/**
* ClientSocket read line (until '\n')
*/
//------------------------------------------------------------
void
ClientSocket
::
readln
(
std
::
string
&
s
,
short
timeout
)
{
string
buf
(
""
);
char
c
=
0
;
while
(
c
!=
'\n'
)
{
readchar
(
c
,
timeout
);
buf
+=
c
;
}
s
=
buf
;
}
//------------------------------------------------------------
/**
* ClientSocket read until terminator received
*/
//------------------------------------------------------------
void
ClientSocket
::
readuntil
(
std
::
string
&
s
,
char
*
terminator
,
short
timeout
)
{
string
buff
(
""
);
string
s_term
(
terminator
);
int
nb
=
0
;
int
term_len
=
strlen
(
terminator
);
char
term_last_char
=
terminator
[
term_len
-
1
];
char
c
;
bool
found
=
false
;
while
(
!
found
)
{
readchar
(
c
,
timeout
);
// Try to get a char.
// OK add to buffer
buff
+=
c
;
nb
++
;
if
(
c
==
term_last_char
&&
nb
>
term_len
)
// Check with terminator
{
// get the end of buffer.
string
::
size_type
pos
=
nb
-
term_len
;
string
s
=
buff
.
substr
(
pos
,
nb
);
// compare with terminator
found
=
(
s
==
s_term
);
}
}
s
=
buff
;
}
//------------------------------------------------------------
/**
* ClientSocket read char with a timeout
*/
//------------------------------------------------------------
void
ClientSocket
::
readchar
(
char
&
c
,
short
timeout
)
{
switch
(
SocketAccess
::
recv
(
c
,
timeout
))
{
case
1
:
return
;
// Ok on char read
case
-
1
:
throw
SocketException
(
"Socket Timeout"
);
default:
throw
SocketException
(
"Read Socket Failed"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment