diff options
-rw-r--r-- | decoder/Makefile.am | 7 | ||||
-rw-r--r-- | decoder/feed.cc | 53 | ||||
-rwxr-xr-x | decoder/feed.rb | 22 | ||||
-rw-r--r-- | decoder/nn.hpp | 204 |
4 files changed, 2 insertions, 284 deletions
diff --git a/decoder/Makefile.am b/decoder/Makefile.am index dcc518bc..8398411e 100644 --- a/decoder/Makefile.am +++ b/decoder/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = cdec minimal_decoder network_decoder feed +bin_PROGRAMS = cdec minimal_decoder network_decoder noinst_PROGRAMS = \ trule_test \ @@ -29,10 +29,7 @@ minimal_decoder_LDADD = libcdec.a ../utils/libutils.a network_decoder_SOURCES = network_decoder.cc nn.hpp network_decoder_LDADD = libcdec.a ../klm/search/libksearch.a ../mteval/libmteval.a ../utils/libutils.a ../klm/lm/libklm.a ../klm/util/libklm_util.a ../klm/util/double-conversion/libklm_util_double.a /usr/lib64/libnanomsg.so -feed_SOURCES = feed.cc nn.hpp -feed_LDADD = /usr/lib64/libnanomsg.so - -AM_CPPFLAGS = -DTEST_DATA=\"$(top_srcdir)/decoder/test_data\" -DBOOST_TEST_DYN_LINK -W -Wno-sign-compare -I$(top_srcdir) -I$(top_srcdir)/mteval -I$(top_srcdir)/utils -I$(top_srcdir)/klm +AM_CPPFLAGS = -DTEST_DATA=\"$(top_srcdir)/decoder/test_data\" -DBOOST_TEST_DYN_LINK -W -Wno-sign-compare -I$(top_srcdir) -I$(top_srcdir)/mteval -I$(top_srcdir)/utils -I$(top_srcdir)/klm -I/fast_scratch/simianer/lfpe/nanomsg-0.5-beta/include -I/fast_scratch/simianer/lfpe/cppnanomsg rule_lexer.cc: rule_lexer.ll $(LEX) -s -CF -8 -o$@ $< diff --git a/decoder/feed.cc b/decoder/feed.cc deleted file mode 100644 index f8923fc4..00000000 --- a/decoder/feed.cc +++ /dev/null @@ -1,53 +0,0 @@ -#include <iostream> -#include <string> -#include <sstream> -#include <stdio.h> -#include <unistd.h> - -#include <nanomsg/nn.h> -#include <nanomsg/pair.h> -#include "nn.hpp" - -using namespace std; - -void -recv(nn::socket& sock) -{ - char *buf = NULL; - size_t sz = sock.recv(&buf, NN_MSG, 0); - if (buf) { - string translation(buf, buf+sz); - cout << "got translation '" << translation << "'" << endl << endl; - } -} - -void -send(nn::socket& sock, const string& msg) -{ - cout << "sending source '" << msg << "'" << endl; - sock.send(msg.c_str(), msg.size()+1, 0); -} - -void -loop(nn::socket& sock) -{ - int to = 100; - sock.setsockopt(NN_SOL_SOCKET, NN_RCVTIMEO, &to, sizeof(to)); - for (string line; getline(cin, line);) { - send(sock, line); - sleep(1); - recv(sock); - } -} - -int main(int argc, char const* argv[]) -{ - nn::socket sock(AF_SP, NN_PAIR); - //string url = "ipc:///tmp/network_decoder.ipc"; - string url = "tcp://127.0.0.1:60666"; - sock.connect(url.c_str()); - loop(sock); - - return 0; -} - diff --git a/decoder/feed.rb b/decoder/feed.rb deleted file mode 100755 index 5ea9737d..00000000 --- a/decoder/feed.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby - -require 'nanomsg' - -port = 60666 -sock = NanoMsg::PairSocket.new -addr = "tcp://127.0.0.1:#{port}" -#addr = "ipc:///tmp/network_decoder.ipc" -sock.connect addr - -while true - line = STDIN.gets - if !line - sock.send 'shutdown' - break - end - puts "sending source '#{line.strip}'" - sock.send line.strip - sleep 1 - puts "got translation: #{sock.recv}\n\n" -end - diff --git a/decoder/nn.hpp b/decoder/nn.hpp deleted file mode 100644 index 50b8304c..00000000 --- a/decoder/nn.hpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - Copyright (c) 2013 250bpm s.r.o. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom - the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. -*/ - -#ifndef NN_HPP_INCLUDED -#define NN_HPP_INCLUDED - -#include <nanomsg/nn.h> - -#include <cassert> -#include <cstring> -#include <algorithm> -#include <exception> - -#if defined __GNUC__ -#define nn_slow(x) __builtin_expect ((x), 0) -#else -#define nn_slow(x) (x) -#endif - -namespace nn -{ - - class exception : public std::exception - { - public: - - exception () : err (nn_errno ()) {} - - virtual const char *what () const throw () - { - return nn_strerror (err); - } - - int num () const - { - return err; - } - - private: - - int err; - }; - - inline const char *symbol (int i, int *value) - { - return nn_symbol (i, value); - } - - inline void *allocmsg (size_t size, int type) - { - void *msg = nn_allocmsg (size, type); - if (nn_slow (!msg)) - throw nn::exception (); - return msg; - } - - inline int freemsg (void *msg) - { - int rc = nn_freemsg (msg); - if (nn_slow (rc != 0)) - throw nn::exception (); - return rc; - } - - class socket - { - public: - - inline socket (int domain, int protocol) - { - s = nn_socket (domain, protocol); - if (nn_slow (s < 0)) - throw nn::exception (); - } - - inline ~socket () - { - int rc = nn_close (s); - assert (rc == 0); - } - - inline void setsockopt (int level, int option, const void *optval, - size_t optvallen) - { - int rc = nn_setsockopt (s, level, option, optval, optvallen); - if (nn_slow (rc != 0)) - throw nn::exception (); - } - - inline void getsockopt (int level, int option, void *optval, - size_t *optvallen) - { - int rc = nn_getsockopt (s, level, option, optval, optvallen); - if (nn_slow (rc != 0)) - throw nn::exception (); - } - - inline int bind (const char *addr) - { - int rc = nn_bind (s, addr); - if (nn_slow (rc < 0)) - throw nn::exception (); - return rc; - } - - inline int connect (const char *addr) - { - int rc = nn_connect (s, addr); - if (nn_slow (rc < 0)) - throw nn::exception (); - return rc; - } - - inline void shutdown (int how) - { - int rc = nn_shutdown (s, how); - if (nn_slow (rc != 0)) - throw nn::exception (); - } - - inline int send (const void *buf, size_t len, int flags) - { - int rc = nn_send (s, buf, len, flags); - if (nn_slow (rc < 0)) { - if (nn_slow (nn_errno () != EAGAIN)) - throw nn::exception (); - return -1; - } - return rc; - } - - inline int recv (void *buf, size_t len, int flags) - { - int rc = nn_recv (s, buf, len, flags); - if (nn_slow (rc < 0)) { - if (nn_slow (nn_errno () != EAGAIN)) - throw nn::exception (); - return -1; - } - return rc; - } - - inline int sendmsg (const struct nn_msghdr *msghdr, int flags) - { - int rc = nn_sendmsg (s, msghdr, flags); - if (nn_slow (rc < 0)) { - if (nn_slow (nn_errno () != EAGAIN)) - throw nn::exception (); - return -1; - } - return rc; - } - - inline int recvmsg (struct nn_msghdr *msghdr, int flags) - { - int rc = nn_recvmsg (s, msghdr, flags); - if (nn_slow (rc < 0)) { - if (nn_slow (nn_errno () != EAGAIN)) - throw nn::exception (); - return -1; - } - return rc; - } - - private: - - int s; - - /* Prevent making copies of the socket by accident. */ - socket (const socket&); - void operator = (const socket&); - }; - - inline void term () - { - nn_term (); - } - -} - -#undef nn_slow - -#endif - - |