Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
4914e5c9
Commit
4914e5c9
authored
Sep 02, 2009
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
O(1) socket removal
parent
f92de9b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
app_thread.cpp
src/app_thread.cpp
+6
-6
socket_base.cpp
src/socket_base.cpp
+13
-1
socket_base.hpp
src/socket_base.hpp
+7
-0
No files found.
src/app_thread.cpp
View file @
4914e5c9
...
...
@@ -138,16 +138,16 @@ zmq::socket_base_t *zmq::app_thread_t::create_socket (int type_)
// TODO: type is ignored for the time being.
socket_base_t
*
s
=
new
socket_base_t
(
this
);
zmq_assert
(
s
);
s
->
set_index
(
sockets
.
size
());
sockets
.
push_back
(
s
);
return
s
;
}
void
zmq
::
app_thread_t
::
remove_socket
(
socket_base_t
*
socket_
)
{
// TODO: To speed this up we can possibly use the system where each socket
// holds its index (see I/O scheduler implementation).
sockets_t
::
iterator
it
=
std
::
find
(
sockets
.
begin
(),
sockets
.
end
(),
socket_
);
zmq_assert
(
it
!=
sockets
.
end
());
sockets
.
erase
(
it
);
int
i
=
socket_
->
get_index
();
socket_
->
set_index
(
-
1
);
sockets
[
i
]
=
sockets
.
back
();
sockets
[
i
]
->
set_index
(
i
);
sockets
.
pop_back
();
}
src/socket_base.cpp
View file @
4914e5c9
...
...
@@ -42,7 +42,8 @@ zmq::socket_base_t::socket_base_t (app_thread_t *parent_) :
pending_term_acks
(
0
),
ticks
(
0
),
app_thread
(
parent_
),
shutting_down
(
false
)
shutting_down
(
false
),
index
(
-
1
)
{
}
...
...
@@ -379,6 +380,17 @@ void zmq::socket_base_t::detach_outpipe (class writer_t *pipe_)
out_pipes
.
pop_back
();
}
void
zmq
::
socket_base_t
::
set_index
(
int
index_
)
{
index
=
index_
;
}
int
zmq
::
socket_base_t
::
get_index
()
{
zmq_assert
(
index
!=
-
1
);
return
index
;
}
void
zmq
::
socket_base_t
::
process_own
(
owned_t
*
object_
)
{
io_objects
.
insert
(
object_
);
...
...
src/socket_base.hpp
View file @
4914e5c9
...
...
@@ -66,6 +66,10 @@ namespace zmq
void
detach_inpipe
(
class
reader_t
*
pipe_
);
void
detach_outpipe
(
class
writer_t
*
pipe_
);
// Manipulating index in the app_thread's list of sockets.
void
set_index
(
int
index
);
int
get_index
();
private
:
// Handlers for incoming commands.
...
...
@@ -131,6 +135,9 @@ namespace zmq
sessions_t
sessions
;
mutex_t
sessions_sync
;
// Index of the socket in the app_thread's list of sockets.
int
index
;
socket_base_t
(
const
socket_base_t
&
);
void
operator
=
(
const
socket_base_t
&
);
};
...
...
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