Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
73f36858
Commit
73f36858
authored
Jan 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/SocketMonitor: add methods Read(), Write()
parent
fe3f0332
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
27 deletions
+43
-27
BufferedSocket.cxx
src/event/BufferedSocket.cxx
+3
-21
BufferedSocket.hxx
src/event/BufferedSocket.hxx
+0
-6
SocketMonitor.cxx
src/event/SocketMonitor.cxx
+32
-0
SocketMonitor.hxx
src/event/SocketMonitor.hxx
+8
-0
No files found.
src/event/BufferedSocket.cxx
View file @
73f36858
...
...
@@ -26,11 +26,6 @@
#include <stdint.h>
#include <string.h>
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#endif
BufferedSocket
::~
BufferedSocket
()
{
if
(
input
!=
nullptr
)
...
...
@@ -40,15 +35,7 @@ BufferedSocket::~BufferedSocket()
BufferedSocket
::
ssize_t
BufferedSocket
::
DirectWrite
(
const
void
*
data
,
size_t
length
)
{
int
flags
=
0
;
#ifdef MSG_NOSIGNAL
flags
|=
MSG_NOSIGNAL
;
#endif
#ifdef MSG_DONTWAIT
flags
|=
MSG_DONTWAIT
;
#endif
const
auto
nbytes
=
send
(
Get
(),
(
const
char
*
)
data
,
length
,
flags
);
const
auto
nbytes
=
SocketMonitor
::
Write
((
const
char
*
)
data
,
length
);
if
(
gcc_unlikely
(
nbytes
<
0
))
{
const
auto
code
=
GetSocketError
();
if
(
IsSocketErrorAgain
(
code
))
...
...
@@ -65,15 +52,10 @@ BufferedSocket::DirectWrite(const void *data, size_t length)
return
nbytes
;
}
ssize_t
BufferedSocket
::
ssize_t
BufferedSocket
::
DirectRead
(
void
*
data
,
size_t
length
)
{
int
flags
=
0
;
#ifdef MSG_DONTWAIT
flags
|=
MSG_DONTWAIT
;
#endif
const
auto
nbytes
=
recv
(
Get
(),
(
char
*
)
data
,
length
,
flags
);
const
auto
nbytes
=
SocketMonitor
::
Read
((
char
*
)
data
,
length
);
if
(
gcc_likely
(
nbytes
>
0
))
return
nbytes
;
...
...
src/event/BufferedSocket.hxx
View file @
73f36858
...
...
@@ -25,16 +25,10 @@
#include "util/PeakBuffer.hxx"
#include "gcc.h"
#include <type_traits>
#include <stddef.h>
struct
fifo_buffer
;
class
EventLoop
;
class
BufferedSocket
:
private
SocketMonitor
{
typedef
std
::
make_signed
<
size_t
>::
type
ssize_t
;
fifo_buffer
*
input
;
PeakBuffer
output
;
...
...
src/event/SocketMonitor.cxx
View file @
73f36858
...
...
@@ -25,6 +25,13 @@
#include <assert.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#endif
/*
* GSource methods
*
...
...
@@ -127,3 +134,28 @@ SocketMonitor::Close()
{
close_socket
(
Steal
());
}
SocketMonitor
::
ssize_t
SocketMonitor
::
Read
(
void
*
data
,
size_t
length
)
{
int
flags
=
0
;
#ifdef MSG_DONTWAIT
flags
|=
MSG_DONTWAIT
;
#endif
return
recv
(
Get
(),
(
char
*
)
data
,
length
,
flags
);
}
SocketMonitor
::
ssize_t
SocketMonitor
::
Write
(
const
void
*
data
,
size_t
length
)
{
int
flags
=
0
;
#ifdef MSG_NOSIGNAL
flags
|=
MSG_NOSIGNAL
;
#endif
#ifdef MSG_DONTWAIT
flags
|=
MSG_DONTWAIT
;
#endif
return
send
(
Get
(),
(
const
char
*
)
data
,
length
,
flags
);
}
src/event/SocketMonitor.hxx
View file @
73f36858
...
...
@@ -24,7 +24,10 @@
#include <glib.h>
#include <type_traits>
#include <assert.h>
#include <stddef.h>
#ifdef WIN32
/* ERRORis a WIN32 macro that poisons our namespace; this is a
...
...
@@ -54,6 +57,8 @@ public:
static
constexpr
unsigned
ERROR
=
G_IO_ERR
;
static
constexpr
unsigned
HANGUP
=
G_IO_HUP
;
typedef
std
::
make_signed
<
size_t
>::
type
ssize_t
;
SocketMonitor
(
EventLoop
&
_loop
)
:
fd
(
-
1
),
loop
(
_loop
),
source
(
nullptr
)
{}
...
...
@@ -106,6 +111,9 @@ public:
poll
.
events
&=
~
WRITE
;
}
ssize_t
Read
(
void
*
data
,
size_t
length
);
ssize_t
Write
(
const
void
*
data
,
size_t
length
);
protected
:
virtual
void
OnSocketReady
(
unsigned
flags
)
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment