Skip to content

Commit

Permalink
Added simple client to go with the simple server
Browse files Browse the repository at this point in the history
Added a simple client to go along with the simple server. Updated
the project model and re-ran project scripts.
  • Loading branch information
danriegsecker committed Dec 9, 2014
1 parent 3c92442 commit 8fdee31
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Please refer to the README for information about making permanent changes. #
################################################################################
MAN1 = filemq_server.1
MAN1 = filemq_server.1 filemq_client.1
MAN3 = fmq_msg.3 fmq_server.3 fmq_client.3
MAN7 = filemq.7
MAN_DOC = $(MAN1) $(MAN3) $(MAN7)
Expand Down
14 changes: 14 additions & 0 deletions doc/filemq_client.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### filemq_client - no title found

Please add @header section in ../src/filemq_client.c.

Please add @discuss section in ../src/filemq_client.c.

This is the class interface:

Please add @interface section in ../src/filemq_client.c.

This is the class self test code:

Please add @selftest section in ../src/filemq_client.c.

26 changes: 26 additions & 0 deletions doc/filemq_client.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
filemq_client(1)
================

NAME
----
filemq_client - no title found

SYNOPSIS
--------
----
Please add @interface section in ../src/filemq_client.c.
----

DESCRIPTION
-----------

Please add @header section in ../src/filemq_client.c.

Please add @discuss section in ../src/filemq_client.c.

EXAMPLE
-------
.From filemq_client_test method
----
Please add @selftest section in ../src/filemq_client.c.
----
1 change: 1 addition & 0 deletions project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
-->

<main name = "filemq_server">Very simple server</main>
<main name = "filemq_client">Very simple client</main>

<!--
Models that we build using GSL.
Expand Down
8 changes: 8 additions & 0 deletions src/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ src_filemq_server_LDADD = ${program_libs}

src_filemq_server_SOURCES = src/filemq_server.c

bin_PROGRAMS += src/filemq_client

src_filemq_client_CPPFLAGS = ${AM_CPPFLAGS}

src_filemq_client_LDADD = ${program_libs}

src_filemq_client_SOURCES = src/filemq_client.c


check_PROGRAMS += src/filemq_selftest

Expand Down
51 changes: 51 additions & 0 deletions src/filemq_client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#include "filemq_classes.h"

int main (int argc, char *argv [])
{
if (argc < 2) {
puts ("usage: filemq_client inbox-dir");
return 0;
}

// Create the client
fmq_client_t *client = fmq_client_new ("tcp://localhost:5670", 1000);
assert (client);
fmq_client_verbose (client);

// Set the clients storage location
int rc = fmq_client_set_inbox (client, argv [1]);
assert (rc >= 0);

// Subscribe to the server's root
rc = fmq_client_subscribe (client, "/");
assert (rc >= 0);

// Get a reference to the msgpipe
zsock_t *msgpipe = fmq_client_msgpipe (client);
assert (msgpipe);

// Setup a poller
zpoller_t *poller = zpoller_new ( (void *) msgpipe, NULL);
assert (poller);

while (!zsys_interrupted) {
void *sock = zpoller_wait (poller, 100);

if (sock == msgpipe) {
zmsg_t *msg = zmsg_recv ( (void *) msgpipe);
zmsg_print (msg);
zmsg_destroy (&msg);
}
else
if (zpoller_terminated (poller)) {
puts ("the poller terminated");
break;
}
}
puts ("interrupted");

zpoller_destroy (&poller);
fmq_client_destroy (&client);
return 0;
}
1 change: 0 additions & 1 deletion src/filemq_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ int main (int argc, char *argv [])
zactor_t *server = zactor_new (fmq_server, "filemq_server");

//zstr_send (server, "VERBOSE");
//zstr_sendx (server, "PUBLISH", "./fmqserv", "/", NULL);
zstr_sendx (server, "PUBLISH", argv [1], "/", NULL);
zstr_sendx (server, "BIND", "tcp://*:5670", NULL);

Expand Down
3 changes: 3 additions & 0 deletions src/fmq_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ get_next_patch_for_client (client_t *self)
zsys_debug ("~~~ current patch is delete ~~~");
fmq_msg_set_sequence (self->message, self->sequence++);
fmq_msg_set_operation (self->message, FMQ_MSG_FILE_DELETE);
fmq_msg_set_eof (self->message, 0);

// No reliability in this version, assume patch delivered safely
zdir_patch_destroy (&self->patch);
Expand Down Expand Up @@ -607,13 +608,15 @@ get_next_patch_for_client (client_t *self)
fmq_msg_set_sequence (self->message, self->sequence++);
fmq_msg_set_operation (self->message, FMQ_MSG_FILE_CREATE);
fmq_msg_set_offset (self->message, self->offset);
fmq_msg_set_eof (self->message, 0);

self->offset += zchunk_size (chunk);
self->credit -= zchunk_size (chunk);

// Zero-sized chunk means end of file
if (zchunk_size (chunk) == 0) {
zsys_debug ("~~~ chunk is empty ~~~");
fmq_msg_set_eof (self->message, 1);
zfile_destroy (&self->file);
zdir_patch_destroy (&self->patch);
}
Expand Down

0 comments on commit 8fdee31

Please sign in to comment.