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
176879e5
Commit
176879e5
authored
Aug 30, 2009
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
engine virtualised; chatroom example removed
parent
1d650934
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
67 additions
and
229 deletions
+67
-229
.gitignore
.gitignore
+5
-0
Makefile.am
Makefile.am
+2
-3
configure.in
configure.in
+1
-2
Makefile.am
examples/Makefile.am
+0
-2
Makefile.am
examples/chat/Makefile.am
+0
-15
chatroom.cpp
examples/chat/chatroom.cpp
+0
-74
display.cpp
examples/chat/display.cpp
+0
-55
prompt.cpp
examples/chat/prompt.cpp
+0
-61
Makefile.am
src/Makefile.am
+1
-0
command.hpp
src/command.hpp
+1
-1
i_engine.hpp
src/i_engine.hpp
+43
-0
object.cpp
src/object.cpp
+2
-3
object.hpp
src/object.hpp
+2
-2
owned.cpp
src/owned.cpp
+1
-1
owned.hpp
src/owned.hpp
+1
-1
session.cpp
src/session.cpp
+2
-2
session.hpp
src/session.hpp
+2
-2
zmq_engine.hpp
src/zmq_engine.hpp
+4
-5
No files found.
.gitignore
View file @
176879e5
COPYING
INSTALL
*.m4
*.o
*.lo
*.loT
*.la
.*
Makefile.am
View file @
176879e5
include_HEADERS
=
include/zmq.h include/zmq.hpp
if
BUILD_PYTHON
DIR_P
=
python
endif
...
...
@@ -9,5 +8,5 @@ if BUILD_RUBY
DIR_R
=
ruby
endif
SUBDIRS
=
src
examples
$(DIR_P)
$(DIR_R)
DIST_SUBDIRS
=
src
examples
$(DIR_P)
$(DIR_R)
SUBDIRS
=
src
$(DIR_P)
$(DIR_R)
DIST_SUBDIRS
=
src
$(DIR_P)
$(DIR_R)
configure.in
View file @
176879e5
...
...
@@ -275,8 +275,7 @@ AC_FUNC_MALLOC
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(perror gettimeofday memset socket getifaddrs freeifaddrs)
AC_OUTPUT(Makefile src/Makefile examples/Makefile examples/chat/Makefile python/Makefile \
python/setup.py ruby/Makefile)
AC_OUTPUT(Makefile src/Makefile python/Makefile python/setup.py ruby/Makefile)
AC_MSG_RESULT([])
AC_MSG_RESULT([ ******************************************************** ])
...
...
examples/Makefile.am
deleted
100644 → 0
View file @
1d650934
SUBDIRS
=
chat
DIST_SUBDIRS
=
chat
examples/chat/Makefile.am
deleted
100644 → 0
View file @
1d650934
INCLUDES
=
-I
$(top_builddir)
-I
$(top_builddir)
/include
noinst_PROGRAMS
=
chatroom display prompt
chatroom_SOURCES
=
chatroom.cpp
chatroom_LDADD
=
$(top_builddir)
/src/libzmq.la
chatroom_CXXFLAGS
=
-Wall
-pedantic
-Werror
display_SOURCES
=
display.cpp
display_LDADD
=
$(top_builddir)
/src/libzmq.la
display_CXXFLAGS
=
-Wall
-pedantic
-Werror
prompt_SOURCES
=
prompt.cpp
prompt_LDADD
=
$(top_builddir)
/src/libzmq.la
prompt_CXXFLAGS
=
-Wall
-pedantic
-Werror
examples/chat/chatroom.cpp
deleted
100644 → 0
View file @
1d650934
/*
Copyright (c) 2007-2009 FastMQ Inc.
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <time.h>
#include <string.h>
#include <iostream>
using
namespace
std
;
#include <zmq.hpp>
int
main
(
int
argc
,
const
char
*
argv
[])
{
// Check the command line syntax
if
(
argc
!=
3
)
{
cerr
<<
"usage: chatroom <in-interface> <out-interface>"
<<
endl
;
return
1
;
}
// Retrieve command line arguments
const
char
*
in_interface
=
argv
[
1
];
const
char
*
out_interface
=
argv
[
2
];
// Initialise 0MQ infrastructure
zmq
::
context_t
ctx
(
1
,
1
);
// Create two sockets. One for receiving messages from 'propmt'
// applications, one for sending messages to 'display' applications
zmq
::
socket_t
in_socket
(
ctx
,
ZMQ_SUB
);
in_socket
.
bind
(
in_interface
);
zmq
::
socket_t
out_socket
(
ctx
,
ZMQ_PUB
);
out_socket
.
bind
(
out_interface
);
while
(
true
)
{
// Get a message
zmq
::
message_t
in_message
;
in_socket
.
recv
(
&
in_message
);
// Get the current time. Replace the newline character at the end
// by space character.
char
timebuf
[
256
];
time_t
current_time
;
time
(
&
current_time
);
snprintf
(
timebuf
,
256
,
"%s"
,
ctime
(
&
current_time
));
timebuf
[
strlen
(
timebuf
)
-
1
]
=
' '
;
// Create and fill in the message
zmq
::
message_t
out_message
(
strlen
(
timebuf
)
+
in_message
.
size
());
char
*
data
=
(
char
*
)
out_message
.
data
();
memcpy
(
data
,
timebuf
,
strlen
(
timebuf
));
data
+=
strlen
(
timebuf
);
memcpy
(
data
,
in_message
.
data
(),
in_message
.
size
());
// Send the message
out_socket
.
send
(
out_message
);
}
}
examples/chat/display.cpp
deleted
100644 → 0
View file @
1d650934
/*
Copyright (c) 2007-2009 FastMQ Inc.
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <string>
#include <iostream>
using
namespace
std
;
#include <zmq.hpp>
int
main
(
int
argc
,
const
char
*
argv
[])
{
// Check the command line syntax.
if
(
argc
!=
2
)
{
cerr
<<
"usage: display <chatroom-out-address>"
<<
endl
;
return
1
;
}
// Retrieve command line arguments
const
char
*
chatroom_out_address
=
argv
[
1
];
// Initialise 0MQ infrastructure, connect to the chatroom and ask for all
// messages and gap notifications.
zmq
::
context_t
ctx
(
1
,
1
);
zmq
::
socket_t
s
(
ctx
,
ZMQ_SUB
);
s
.
connect
(
chatroom_out_address
);
while
(
true
)
{
// Get a message and print it to the console.
zmq
::
message_t
message
;
s
.
recv
(
&
message
);
if
(
message
.
type
()
==
zmq
::
message_gap
)
cout
<<
"Problems connecting to the chatroom..."
<<
endl
;
else
cout
<<
(
char
*
)
message
.
data
()
<<
flush
;
}
}
examples/chat/prompt.cpp
deleted
100644 → 0
View file @
1d650934
/*
Copyright (c) 2007-2009 FastMQ Inc.
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <string>
#include <iostream>
using
namespace
std
;
#include <zmq.hpp>
int
main
(
int
argc
,
const
char
*
argv
[])
{
// Check the command line syntax.
if
(
argc
!=
3
)
{
cerr
<<
"usage: prompt <chatroom-in-address> <user name>"
<<
endl
;
return
1
;
}
// Retrieve command line arguments
const
char
*
chatroom_in_address
=
argv
[
1
];
const
char
*
user_name
=
argv
[
2
];
// Initialise 0MQ infrastructure and connect to the chatroom.
zmq
::
context_t
ctx
(
1
,
1
);
zmq
::
socket_t
s
(
ctx
,
ZMQ_PUB
);
s
.
connect
(
chatroom_in_address
);
while
(
true
)
{
// Allow user to input the message text. Prepend it by user name.
char
textbuf
[
1024
];
char
*
rcc
=
fgets
(
textbuf
,
sizeof
(
textbuf
),
stdin
);
assert
(
rcc
);
string
text
(
user_name
);
text
=
text
+
": "
+
textbuf
;
// Create the message (terminating zero is part of the message)
zmq
::
message_t
message
(
text
.
size
()
+
1
);
memcpy
(
message
.
data
(),
text
.
c_str
(),
text
.
size
()
+
1
);
// Send the message
s
.
send
(
message
);
}
}
src/Makefile.am
View file @
176879e5
...
...
@@ -20,6 +20,7 @@ libzmq_la_SOURCES = \
io_thread.hpp
\
ip.hpp
\
i_endpoint.hpp
\
i_engine.hpp
\
i_poller.hpp
\
i_poll_events.hpp
\
i_signaler.hpp
\
...
...
src/command.hpp
View file @
176879e5
...
...
@@ -65,7 +65,7 @@ namespace zmq
// Attach the engine to the session.
struct
{
class
zmq_engine_t
*
engine
;
struct
i_engine
*
engine
;
}
attach
;
// Sent from session to socket to establish pipe(s) between them.
...
...
src/i_engine.hpp
0 → 100644
View file @
176879e5
/*
Copyright (c) 2007-2009 FastMQ Inc.
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ZMQ_I_ENGINE_HPP_INCLUDED__
#define __ZMQ_I_ENGINE_HPP_INCLUDED__
namespace
zmq
{
struct
i_engine
{
virtual
~
i_engine
()
{}
// Plug the engine to the session.
virtual
void
plug
(
struct
i_inout
*
inout_
)
=
0
;
// Unplug the engine from the session.
virtual
void
unplug
()
=
0
;
// This method is called by the session to signalise that there
// are messages to send available.
virtual
void
revive
()
=
0
;
};
}
#endif
src/object.cpp
View file @
176879e5
...
...
@@ -26,7 +26,6 @@
#include "owned.hpp"
#include "session.hpp"
#include "socket_base.hpp"
#include "zmq_engine.hpp" // TODO: remove this line
zmq
::
object_t
::
object_t
(
dispatcher_t
*
dispatcher_
,
int
thread_slot_
)
:
dispatcher
(
dispatcher_
),
...
...
@@ -153,7 +152,7 @@ void zmq::object_t::send_own (socket_base_t *destination_, owned_t *object_)
send_command
(
cmd
);
}
void
zmq
::
object_t
::
send_attach
(
session_t
*
destination_
,
zmq_engine_t
*
engine_
)
void
zmq
::
object_t
::
send_attach
(
session_t
*
destination_
,
i_engine
*
engine_
)
{
// The assumption here is that command sequence number of the destination
// object was already incremented in find_session function.
...
...
@@ -241,7 +240,7 @@ void zmq::object_t::process_own (owned_t *object_)
zmq_assert
(
false
);
}
void
zmq
::
object_t
::
process_attach
(
zmq_engine_t
*
engine_
)
void
zmq
::
object_t
::
process_attach
(
i_engine
*
engine_
)
{
zmq_assert
(
false
);
}
...
...
src/object.hpp
View file @
176879e5
...
...
@@ -60,7 +60,7 @@ namespace zmq
void
send_own
(
class
socket_base_t
*
destination_
,
class
owned_t
*
object_
);
void
send_attach
(
class
session_t
*
destination_
,
class
zmq_engine_t
*
engine_
);
struct
i_engine
*
engine_
);
void
send_bind
(
object_t
*
destination_
,
class
owned_t
*
session_
,
class
reader_t
*
in_pipe_
,
class
writer_t
*
out_pipe_
);
void
send_revive
(
class
object_t
*
destination_
);
...
...
@@ -76,7 +76,7 @@ namespace zmq
virtual
void
process_stop
();
virtual
void
process_plug
();
virtual
void
process_own
(
class
owned_t
*
object_
);
virtual
void
process_attach
(
class
zmq_engine_t
*
engine_
);
virtual
void
process_attach
(
struct
i_engine
*
engine_
);
virtual
void
process_bind
(
class
owned_t
*
session_
,
class
reader_t
*
in_pipe_
,
class
writer_t
*
out_pipe_
);
virtual
void
process_revive
();
...
...
src/owned.cpp
View file @
176879e5
...
...
@@ -47,7 +47,7 @@ void zmq::owned_t::process_plug ()
finalise_command
();
}
void
zmq
::
owned_t
::
process_attach
(
zmq_engine_t
*
engine_
)
void
zmq
::
owned_t
::
process_attach
(
struct
i_engine
*
engine_
)
{
// Keep track of how many commands were processed so far.
processed_seqnum
++
;
...
...
src/owned.hpp
View file @
176879e5
...
...
@@ -61,7 +61,7 @@ namespace zmq
// It's vital that session invokes io_object_t::process_attach
// at the end of it's own attach handler.
void
process_attach
(
class
zmq_engine_t
*
engine_
);
void
process_attach
(
struct
i_engine
*
engine_
);
// io_object_t defines a new handler used to disconnect the object
// from the poller object. Implement the handlen in the derived
...
...
src/session.cpp
View file @
176879e5
...
...
@@ -18,7 +18,7 @@
*/
#include "session.hpp"
#include "
zmq
_engine.hpp"
#include "
i
_engine.hpp"
#include "err.hpp"
#include "pipe.hpp"
...
...
@@ -149,7 +149,7 @@ void zmq::session_t::process_unplug ()
}
}
void
zmq
::
session_t
::
process_attach
(
class
zmq_engine_t
*
engine_
)
void
zmq
::
session_t
::
process_attach
(
i_engine
*
engine_
)
{
zmq_assert
(
engine_
);
engine
=
engine_
;
...
...
src/session.hpp
View file @
176879e5
...
...
@@ -58,7 +58,7 @@ namespace zmq
// Handlers for incoming commands.
void
process_plug
();
void
process_unplug
();
void
process_attach
(
class
zmq_engine_t
*
engine_
);
void
process_attach
(
struct
i_engine
*
engine_
);
// Inbound pipe, i.e. one the session is getting messages from.
class
reader_t
*
in_pipe
;
...
...
@@ -69,7 +69,7 @@ namespace zmq
// Outbound pipe, i.e. one the socket is sending messages to.
class
writer_t
*
out_pipe
;
class
zmq_engine_t
*
engine
;
struct
i_engine
*
engine
;
// The name of the session. One that is used to register it with
// socket-level repository of sessions.
...
...
src/zmq_engine.hpp
View file @
176879e5
...
...
@@ -20,6 +20,7 @@
#ifndef __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__
#define __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__
#include "i_engine.hpp"
#include "io_object.hpp"
#include "tcp_socket.hpp"
#include "zmq_encoder.hpp"
...
...
@@ -28,24 +29,22 @@
namespace
zmq
{
class
zmq_engine_t
:
public
io_object_t
class
zmq_engine_t
:
public
io_object_t
,
public
i_engine
{
public
:
zmq_engine_t
(
class
io_thread_t
*
parent_
,
fd_t
fd_
);
~
zmq_engine_t
();
// i_engine interface implementation.
void
plug
(
struct
i_inout
*
inout_
);
void
unplug
();
void
revive
();
// i_poll_events interface implementation.
void
in_event
();
void
out_event
();
// This method is called by the session to signalise that there
// are messages to send available.
void
revive
();
private
:
// Function to handle network disconnections.
...
...
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