mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
python binding removed
This commit is contained in:
parent
efefa069b2
commit
45414b5444
@ -2,14 +2,10 @@ if BUILD_JAVA
|
||||
DIR_J = java
|
||||
endif
|
||||
|
||||
if BUILD_PYTHON
|
||||
DIR_P = python
|
||||
endif
|
||||
|
||||
if BUILD_RUBY
|
||||
DIR_R = ruby
|
||||
endif
|
||||
|
||||
SUBDIRS = $(DIR_J) $(DIR_P) $(DIR_R)
|
||||
DIST_SUBDIRS = java python ruby
|
||||
SUBDIRS = $(DIR_J) $(DIR_R)
|
||||
DIST_SUBDIRS = java ruby
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/libzmq \
|
||||
-I$(top_builddir)/libzmq $(PYTHON_INCLUDES)
|
||||
|
||||
pyexec_LTLIBRARIES = libpyzmq.la
|
||||
libpyzmq_la_SOURCES = pyzmq.cpp
|
||||
libpyzmq_la_LIBADD = $(top_builddir)/src/libzmq.la
|
||||
libpyzmq_la_LDFLAGS = -avoid-version
|
@ -1,556 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2007-2010 iMatix Corporation
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../c/zmq.h"
|
||||
|
||||
#if defined _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable:4996)
|
||||
#endif
|
||||
|
||||
extern PyTypeObject context_type;
|
||||
|
||||
struct context_t
|
||||
{
|
||||
PyObject_HEAD
|
||||
void *handle;
|
||||
};
|
||||
|
||||
PyObject *context_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
context_t *self = (context_t*) type->tp_alloc (type, 0);
|
||||
|
||||
if (self)
|
||||
self->handle = NULL;
|
||||
|
||||
return (PyObject*) self;
|
||||
}
|
||||
|
||||
|
||||
int context_init (context_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
int app_threads;
|
||||
int io_threads;
|
||||
int flags = 0;
|
||||
static const char *kwlist [] = {"app_threads", "io_threads", "flags", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "ii|i", (char**) kwlist,
|
||||
&app_threads, &io_threads, &flags)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert (!self->handle);
|
||||
self->handle = zmq_init (app_threads, io_threads, flags);
|
||||
if (!self->handle) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void context_dealloc (context_t *self)
|
||||
{
|
||||
if (self->handle) {
|
||||
int rc = zmq_term (self->handle);
|
||||
if (rc != 0)
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
}
|
||||
|
||||
self->ob_type->tp_free ((PyObject*) self);
|
||||
}
|
||||
|
||||
extern PyTypeObject socket_type;
|
||||
|
||||
struct socket_t
|
||||
{
|
||||
PyObject_HEAD
|
||||
void *handle;
|
||||
};
|
||||
|
||||
PyObject *socket_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
socket_t *self = (socket_t*) type->tp_alloc (type, 0);
|
||||
|
||||
if (self)
|
||||
self->handle = NULL;
|
||||
|
||||
return (PyObject*) self;
|
||||
}
|
||||
|
||||
int socket_init (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
context_t *context;
|
||||
int socket_type;
|
||||
static const char *kwlist [] = {"context", "type", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "O!i", (char**) kwlist,
|
||||
&context_type, &context, &socket_type)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert (!self->handle);
|
||||
self->handle = zmq_socket (context->handle, socket_type);
|
||||
if (!self->handle) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void socket_dealloc (socket_t *self)
|
||||
{
|
||||
if (self->handle) {
|
||||
int rc = zmq_close (self->handle);
|
||||
if (rc != 0)
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
}
|
||||
|
||||
self->ob_type->tp_free ((PyObject*) self);
|
||||
}
|
||||
|
||||
PyObject *socket_setsockopt (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
int option;
|
||||
PyObject* optval;
|
||||
static const char *kwlist [] = {"option", "optval", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "iO", (char**) kwlist,
|
||||
&option, &optval)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
|
||||
switch (option) {
|
||||
case ZMQ_HWM:
|
||||
case ZMQ_LWM:
|
||||
case ZMQ_SWAP:
|
||||
case ZMQ_AFFINITY:
|
||||
case ZMQ_RATE:
|
||||
case ZMQ_RECOVERY_IVL:
|
||||
case ZMQ_MCAST_LOOP:
|
||||
{
|
||||
int val = PyInt_AsLong (optval);
|
||||
rc = zmq_setsockopt (self->handle, option, &val, sizeof (int));
|
||||
break;
|
||||
}
|
||||
case ZMQ_IDENTITY:
|
||||
case ZMQ_SUBSCRIBE:
|
||||
case ZMQ_UNSUBSCRIBE:
|
||||
rc = zmq_setsockopt (self->handle, option, PyString_AsString (optval),
|
||||
PyString_Size (optval));
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = -1;
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *socket_bind (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
char const *addr;
|
||||
static const char *kwlist [] = {"addr", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "s", (char**) kwlist,
|
||||
&addr)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rc = zmq_bind (self->handle, addr);
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *socket_connect (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
char const *addr;
|
||||
static const char *kwlist [] = {"addr", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "s", (char**) kwlist,
|
||||
&addr)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rc = zmq_connect (self->handle, addr);
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *socket_send (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
PyObject *msg; /* = PyString_FromStringAndSize (NULL, 0); */
|
||||
int flags = 0;
|
||||
static const char *kwlist [] = {"msg", "flags", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "S|i", (char**) kwlist,
|
||||
&msg, &flags)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zmq_msg_t data;
|
||||
int rc = zmq_msg_init_size (&data, PyString_Size (msg));
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
memcpy (zmq_msg_data (&data), PyString_AsString (msg),
|
||||
zmq_msg_size (&data));
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
rc = zmq_send (self->handle, &data, flags);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
int rc2 = zmq_msg_close (&data);
|
||||
assert (rc2 == 0);
|
||||
|
||||
if (rc != 0 && errno == EAGAIN)
|
||||
return PyBool_FromLong (0);
|
||||
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyBool_FromLong (1);
|
||||
}
|
||||
|
||||
PyObject *socket_flush (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
static const char *kwlist [] = {NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "", (char**) kwlist)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rc = zmq_flush (self->handle);
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, zmq_strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *socket_recv (socket_t *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
int flags = 0;
|
||||
static const char *kwlist [] = {"flags", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwdict, "|i", (char**) kwlist,
|
||||
&flags)) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zmq_msg_t msg;
|
||||
int rc = zmq_msg_init (&msg);
|
||||
assert (rc == 0);
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
rc = zmq_recv (self->handle, &msg, flags);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (rc != 0 && errno == EAGAIN) {
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
PyErr_SetString (PyExc_SystemError, "invalid arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *result = PyString_FromStringAndSize ((char*) zmq_msg_data (&msg),
|
||||
zmq_msg_size (&msg));
|
||||
rc = zmq_msg_close (&msg);
|
||||
assert (rc == 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyMethodDef context_methods [] =
|
||||
{
|
||||
{
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
PyTypeObject context_type =
|
||||
{
|
||||
PyObject_HEAD_INIT (NULL)
|
||||
0,
|
||||
"libpyzmq.Context", /* tp_name */
|
||||
sizeof (context_t), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor) context_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
"", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
context_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc) context_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
context_new /* tp_new */
|
||||
};
|
||||
|
||||
static PyMethodDef socket_methods [] =
|
||||
{
|
||||
{
|
||||
"setsockopt",
|
||||
(PyCFunction) socket_setsockopt,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"setsockopt (option, optval) -> None\n\n"
|
||||
},
|
||||
{
|
||||
"bind",
|
||||
(PyCFunction) socket_bind,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"bind (addr) -> None\n\n"
|
||||
},
|
||||
{
|
||||
"connect",
|
||||
(PyCFunction) socket_connect,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"connect (addr) -> None\n\n"
|
||||
},
|
||||
{
|
||||
"send",
|
||||
(PyCFunction) socket_send,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"send (msg, [flags]) -> Bool\n\n"
|
||||
},
|
||||
{
|
||||
"flush",
|
||||
(PyCFunction) socket_flush,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"flush () -> None\n\n"
|
||||
},
|
||||
{
|
||||
"recv",
|
||||
(PyCFunction) socket_recv,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"recv ([flags]) -> String\n\n"
|
||||
},
|
||||
{
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
PyTypeObject socket_type =
|
||||
{
|
||||
PyObject_HEAD_INIT (NULL)
|
||||
0,
|
||||
"libpyzmq.Socket", /* tp_name */
|
||||
sizeof (socket_t), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor) socket_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
0, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
"", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
socket_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc) socket_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
socket_new /* tp_new */
|
||||
};
|
||||
|
||||
static PyMethodDef module_methods [] = {{ NULL, NULL, 0, NULL }};
|
||||
|
||||
static const char* libpyzmq_doc =
|
||||
"Python API for 0MQ lightweight messaging kernel.\n"
|
||||
"For more information see http://www.zeromq.org.\n"
|
||||
"0MQ is distributed under GNU Lesser General Public License v3.\n";
|
||||
|
||||
#ifndef PyMODINIT_FUNC
|
||||
#define PyMODINIT_FUNC void
|
||||
#endif
|
||||
|
||||
PyMODINIT_FUNC initlibpyzmq ()
|
||||
{
|
||||
int rc = PyType_Ready (&context_type);
|
||||
assert (rc == 0);
|
||||
rc = PyType_Ready (&socket_type);
|
||||
assert (rc == 0);
|
||||
|
||||
PyObject *module = Py_InitModule3 ("libpyzmq", module_methods,
|
||||
(char*) libpyzmq_doc);
|
||||
if (!module)
|
||||
return;
|
||||
|
||||
Py_INCREF (&context_type);
|
||||
PyModule_AddObject (module, "Context", (PyObject*) &context_type);
|
||||
Py_INCREF (&socket_type);
|
||||
PyModule_AddObject (module, "Socket", (PyObject*) &socket_type);
|
||||
|
||||
PyObject *dict = PyModule_GetDict (module);
|
||||
assert (dict);
|
||||
PyObject *t;
|
||||
t = PyInt_FromLong (ZMQ_NOBLOCK);
|
||||
PyDict_SetItemString (dict, "NOBLOCK", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_NOFLUSH);
|
||||
PyDict_SetItemString (dict, "NOFLUSH", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_P2P);
|
||||
PyDict_SetItemString (dict, "P2P", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_PUB);
|
||||
PyDict_SetItemString (dict, "PUB", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_SUB);
|
||||
PyDict_SetItemString (dict, "SUB", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_REQ);
|
||||
PyDict_SetItemString (dict, "REQ", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_REP);
|
||||
PyDict_SetItemString (dict, "REP", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_XREQ);
|
||||
PyDict_SetItemString (dict, "XREQ", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_XREP);
|
||||
PyDict_SetItemString (dict, "XREP", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_UPSTREAM);
|
||||
PyDict_SetItemString (dict, "UPSTREAM", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_DOWNSTREAM);
|
||||
PyDict_SetItemString (dict, "DOWNSTREAM", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_HWM);
|
||||
PyDict_SetItemString (dict, "HWM", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_LWM);
|
||||
PyDict_SetItemString (dict, "LWM", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_SWAP);
|
||||
PyDict_SetItemString (dict, "SWAP", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_AFFINITY);
|
||||
PyDict_SetItemString (dict, "AFFINITY", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_IDENTITY);
|
||||
PyDict_SetItemString (dict, "IDENTITY", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_SUBSCRIBE);
|
||||
PyDict_SetItemString (dict, "SUBSCRIBE", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_UNSUBSCRIBE);
|
||||
PyDict_SetItemString (dict, "UNSUBSCRIBE", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_RATE);
|
||||
PyDict_SetItemString (dict, "RATE", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_RECOVERY_IVL);
|
||||
PyDict_SetItemString (dict, "RECOVERY_IVL", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_MCAST_LOOP);
|
||||
PyDict_SetItemString (dict, "MCAST_LOOP", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_SNDBUF);
|
||||
PyDict_SetItemString (dict, "SNDBUF", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_RCVBUF);
|
||||
PyDict_SetItemString (dict, "RCVBUF", t);
|
||||
Py_DECREF (t);
|
||||
t = PyInt_FromLong (ZMQ_POLL);
|
||||
PyDict_SetItemString (dict, "POLL", t);
|
||||
Py_DECREF (t);
|
||||
}
|
||||
|
||||
#if defined _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
from distutils.core import setup, Extension
|
||||
|
||||
module1 = Extension('libpyzmq',
|
||||
libraries = ['zmq'],
|
||||
library_dirs = ['@prefix@/lib'],
|
||||
include_dirs = ['@PYTHON_SETUP_INCLUDES@','@prefix@/include'],
|
||||
sources = ['pyzmq.cpp'])
|
||||
|
||||
setup (name = 'libyzmq',
|
||||
version = '@VERSION@',
|
||||
description = '0MQ Python library',
|
||||
ext_modules = [module1])
|
||||
|
||||
|
65
configure.in
65
configure.in
@ -313,46 +313,6 @@ if test "x$cpp" != "xno"; then
|
||||
cppzmq="yes"
|
||||
fi
|
||||
|
||||
# Python
|
||||
pyzmq="no"
|
||||
AC_ARG_WITH(python_headersdir,
|
||||
AS_HELP_STRING([--with-python-headersdir], [Python.h header file location]),
|
||||
[python_headersdir="$withval"], [python_headersdir="no"])
|
||||
|
||||
AC_ARG_WITH([python], [AS_HELP_STRING([--with-python], [build Python language binding [default=no]])], [with_python=yes], [with_python=no])
|
||||
if test "x$with_python" != "xno"; then
|
||||
AM_PATH_PYTHON([2.4], , [:])
|
||||
if test "x$PYTHON" = "x:"; then
|
||||
AC_MSG_ERROR([the --with-python option requires that python be installled.]);
|
||||
fi
|
||||
|
||||
if test "x$python_headersdir" != "xno"; then
|
||||
PYTHON_INCLUDES="-I${python_headersdir}"
|
||||
PYTHON_SETUP_INCLUDES="${python_headersdir}"
|
||||
|
||||
AC_CHECK_HEADERS($python_headersdir/Python.h, [] ,
|
||||
[AC_MSG_ERROR([cannot find a usable Python.h in ${python_headersdir}.])])
|
||||
|
||||
else
|
||||
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
|
||||
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
|
||||
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
|
||||
PYTHON_SETUP_INCLUDES="${py_prefix}/include/python${PYTHON_VERSION}"
|
||||
|
||||
if test "$py_prefix" != "$py_exec_prefix"; then
|
||||
PYTHON_INCLUDES="${PYTHON_INCLUDES} -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS($py_prefix/include/python${PYTHON_VERSION}/Python.h, [] ,
|
||||
[AC_MSG_ERROR([cannot find a usable Python.h in $py_prefix/include/python${PYTHON_VERSION}.])])
|
||||
fi
|
||||
|
||||
AC_SUBST(PYTHON_INCLUDES)
|
||||
AC_SUBST(PYTHON_SETUP_INCLUDES)
|
||||
|
||||
pyzmq="yes"
|
||||
fi
|
||||
|
||||
# RUBY
|
||||
rbzmq="no"
|
||||
AC_ARG_WITH(ruby_headersdir,
|
||||
@ -394,13 +354,6 @@ fi
|
||||
|
||||
RUBYDIR="$rubydir"
|
||||
AC_SUBST([RUBYDIR])
|
||||
|
||||
if test "x$pyzmq" = "xyes"; then
|
||||
AC_CHECK_PROG(have_python, python, yes, no)
|
||||
if test "x$have_python" != "xyes"; then
|
||||
AC_MSG_ERROR([the --with-python option requires that python be installed.])
|
||||
fi
|
||||
fi
|
||||
|
||||
# Java language binding
|
||||
jzmq="no"
|
||||
@ -523,11 +476,9 @@ if test "x$with_pgm_ext" != "xno"; then
|
||||
if test "x$have_perl" != "xyes"; then
|
||||
AC_MSG_ERROR([perl is required for building the PGM extension.])
|
||||
fi
|
||||
if test "x$pyzmq" != "xyes"; then
|
||||
AC_CHECK_PROG(have_python, python, yes, no)
|
||||
if test "x$have_python" != "xyes"; then
|
||||
AC_MSG_ERROR([python is required for building the PGM extension.])
|
||||
fi
|
||||
AC_CHECK_PROG(have_python, python, yes, no)
|
||||
if test "x$have_python" != "xyes"; then
|
||||
AC_MSG_ERROR([python is required for building the PGM extension.])
|
||||
fi
|
||||
|
||||
# Unpack libpgm
|
||||
@ -586,7 +537,7 @@ AC_ARG_WITH([perf], [AS_HELP_STRING([--with-perf],
|
||||
if test "x$with_perf" != "xno"; then
|
||||
perf="yes"
|
||||
|
||||
if test "x$czmq" = "xno" -a "x$cppzmq" = "xno" -a "x$pyzmq" = "xno" -a \
|
||||
if test "x$czmq" = "xno" -a "x$cppzmq" = "xno" -a \
|
||||
"x$jzmq" = "xno" -a "x$rbzmq" = "xno"; then
|
||||
AC_MSG_ERROR([the --with-perf option requires at least one language binding.]);
|
||||
fi
|
||||
@ -596,9 +547,7 @@ if test "x$with_perf" = "xno" -a "x$with_pgm_examples" = "xyes"; then
|
||||
AC_MSG_ERROR([cannot configure --with-pgm-examples without --with-perf.]);
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_PYTHON, test "x$pyzmq" = "xyes")
|
||||
AM_CONDITIONAL(BUILD_JAVA, test "x$jzmq" = "xyes")
|
||||
AM_CONDITIONAL(BUILD_PYTHON, test "x$pyzmq" = "xyes")
|
||||
AM_CONDITIONAL(BUILD_RUBY, test "x$rbzmq" = "xyes")
|
||||
AM_CONDITIONAL(BUILD_C, test "x$czmq" = "xyes")
|
||||
AM_CONDITIONAL(BUILD_CPP, test "x$cppzmq" = "xyes")
|
||||
@ -625,10 +574,9 @@ AC_SUBST(LIBZMQ_EXTRA_LDFLAGS)
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS(perror gettimeofday memset socket getifaddrs freeifaddrs)
|
||||
|
||||
AC_OUTPUT(Makefile src/Makefile doc/Makefile bindings/python/Makefile \
|
||||
bindings/python/setup.py bindings/ruby/Makefile \
|
||||
AC_OUTPUT(Makefile src/Makefile doc/Makefile bindings/ruby/Makefile \
|
||||
bindings/java/Makefile perf/Makefile perf/c/Makefile perf/cpp/Makefile \
|
||||
perf/python/Makefile perf/ruby/Makefile perf/java/Makefile src/libzmq.pc \
|
||||
perf/ruby/Makefile perf/java/Makefile src/libzmq.pc \
|
||||
devices/Makefile devices/zmq_forwarder/Makefile \
|
||||
devices/zmq_streamer/Makefile devices/zmq_queue/Makefile bindings/Makefile)
|
||||
|
||||
@ -657,7 +605,6 @@ AC_MSG_RESULT([ Language bindings:])
|
||||
AC_MSG_RESULT([ C: $czmq])
|
||||
AC_MSG_RESULT([ C++: $cppzmq])
|
||||
AC_MSG_RESULT([ Java: $jzmq])
|
||||
AC_MSG_RESULT([ Python: $pyzmq])
|
||||
AC_MSG_RESULT([ Ruby: $rbzmq])
|
||||
if test "x$rbzmq" = "xyes"; then
|
||||
AC_MSG_RESULT([ Ruby library install dir: $rubydir])
|
||||
|
@ -5,7 +5,7 @@ MAN3 = zmq_bind.3 zmq_close.3 zmq_connect.3 zmq_flush.3 zmq_init.3 \
|
||||
zmq_poll.3 zmq_recv.3 zmq_send.3 zmq_setsockopt.3 zmq_socket.3 \
|
||||
zmq_strerror.3 zmq_term.3 zmq_version.3
|
||||
MAN7 = zmq.7 zmq_tcp.7 zmq_udp.7 zmq_pgm.7 zmq_inproc.7 zmq_ipc.7 \
|
||||
zmq_cpp.7 zmq_java.7 zmq_python.7
|
||||
zmq_cpp.7 zmq_java.7
|
||||
MAN_DOC = $(MAN1) $(MAN3) $(MAN7)
|
||||
|
||||
MAN_TXT = $(MAN1:%.1=%.txt)
|
||||
|
@ -166,9 +166,6 @@ $$C++$$::
|
||||
Java::
|
||||
linkzmq:zmq_java[7]
|
||||
|
||||
Python::
|
||||
linkzmq:zmq_python[7]
|
||||
|
||||
|
||||
AUTHOR
|
||||
------
|
||||
|
@ -1,27 +0,0 @@
|
||||
zmq_python(7)
|
||||
=============
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
zmq_python - interface between 0MQ and Python applications
|
||||
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
*
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
*
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
*
|
||||
|
||||
|
||||
AUTHOR
|
||||
------
|
||||
Martin Sustrik <sustrik at 250bpm dot com>
|
@ -6,10 +6,6 @@ if BUILD_CPP
|
||||
PERF_DIR_CPP = cpp
|
||||
endif
|
||||
|
||||
if BUILD_PYTHON
|
||||
PERF_DIR_P = python
|
||||
endif
|
||||
|
||||
if BUILD_JAVA
|
||||
PERF_DIR_J = java
|
||||
endif
|
||||
@ -18,6 +14,5 @@ if BUILD_RUBY
|
||||
PERF_DIR_R = ruby
|
||||
endif
|
||||
|
||||
SUBDIRS = $(PERF_DIR_C) $(PERF_DIR_CPP) $(PERF_DIR_P) \
|
||||
$(PERF_DIR_J) $(PERF_DIR_R)
|
||||
DIST_SUBDIRS = c cpp python java ruby
|
||||
SUBDIRS = $(PERF_DIR_C) $(PERF_DIR_CPP) $(PERF_DIR_J) $(PERF_DIR_R)
|
||||
DIST_SUBDIRS = c cpp java ruby
|
||||
|
@ -1 +0,0 @@
|
||||
EXTRA_DIST = *.py
|
@ -1,49 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2007-2010 iMatix Corporation
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import libpyzmq
|
||||
|
||||
def main ():
|
||||
if len (sys.argv) != 4:
|
||||
print 'usage: local_lat <bind-to> <message-size> <roundtrip-count>'
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
bind_to = sys.argv [1]
|
||||
message_size = int (sys.argv [2])
|
||||
roundtrip_count = int (sys.argv [3])
|
||||
except (ValueError, OverflowError), e:
|
||||
print 'message-size and roundtrip-count must be integers'
|
||||
sys.exit (1)
|
||||
|
||||
ctx = libpyzmq.Context (1, 1);
|
||||
s = libpyzmq.Socket (ctx, libpyzmq.REP)
|
||||
s.bind (bind_to)
|
||||
|
||||
for i in range (0, roundtrip_count):
|
||||
msg = s.recv ()
|
||||
assert len (msg) == message_size
|
||||
s.send (msg)
|
||||
|
||||
time.sleep (1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main ()
|
@ -1,70 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2007-2010 iMatix Corporation
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import libpyzmq
|
||||
|
||||
def main ():
|
||||
if len (sys.argv) != 4:
|
||||
print 'usage: local_thr <bind-to> <message-size> <message-count>'
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
bind_to = sys.argv [1]
|
||||
message_size = int (sys.argv [2])
|
||||
message_count = int (sys.argv [3])
|
||||
except (ValueError, OverflowError), e:
|
||||
print 'message-size and message-count must be integers'
|
||||
sys.exit (1)
|
||||
|
||||
ctx = libpyzmq.Context (1, 1);
|
||||
s = libpyzmq.Socket (ctx, libpyzmq.SUB)
|
||||
|
||||
s.setsockopt (libpyzmq.SUBSCRIBE , "");
|
||||
|
||||
# Add your socket options here.
|
||||
# For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
||||
|
||||
s.bind (bind_to)
|
||||
|
||||
msg = s.recv ()
|
||||
assert len (msg) == message_size
|
||||
|
||||
start = time.clock ()
|
||||
|
||||
for i in range (1, message_count):
|
||||
msg = s.recv ()
|
||||
assert len (msg) == message_size
|
||||
|
||||
end = time.clock ()
|
||||
|
||||
elapsed = (end - start) * 1000000
|
||||
if elapsed == 0:
|
||||
elapsed = 1
|
||||
throughput = (1000000.0 * float (message_count)) / float (elapsed)
|
||||
megabits = float (throughput * message_size * 8) / 1000000
|
||||
|
||||
print "message size: %.0f [B]" % (message_size, )
|
||||
print "message count: %.0f" % (message_count, )
|
||||
print "mean throughput: %.0f [msg/s]" % (throughput, )
|
||||
print "mean throughput: %.3f [Mb/s]" % (megabits, )
|
||||
|
||||
if __name__ == "__main__":
|
||||
main ()
|
@ -1,61 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2007-2010 iMatix Corporation
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
import sys
|
||||
import time
|
||||
import libpyzmq
|
||||
|
||||
def main ():
|
||||
if len(sys.argv) != 4:
|
||||
print 'usage: remote_lat <connect-to> <message-size> <roundtrip-count>'
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
connect_to = sys.argv [1]
|
||||
message_size = int (sys.argv [2])
|
||||
roundtrip_count = int (sys.argv [3])
|
||||
except (ValueError, OverflowError), e:
|
||||
print 'message-size and message-count must be integers'
|
||||
sys.exit (1)
|
||||
|
||||
ctx = libpyzmq.Context (1, 1);
|
||||
s = libpyzmq.Socket (ctx, libpyzmq.REQ)
|
||||
s.connect (connect_to)
|
||||
|
||||
msg = ''.join ([' ' for n in range (0, message_size)])
|
||||
|
||||
start = time.clock ()
|
||||
|
||||
for i in range (0, roundtrip_count):
|
||||
s.send (msg)
|
||||
msg = s.recv ()
|
||||
assert len (msg) == message_size
|
||||
|
||||
end = time.clock ()
|
||||
|
||||
elapsed = (end - start) * 1000000
|
||||
latency = elapsed / roundtrip_count / 2
|
||||
|
||||
print "message size: %.0f [B]" % (message_size, )
|
||||
print "roundtrip count: %.0f" % (roundtrip_count, )
|
||||
print "mean latency: %.3f [us]" % (latency, )
|
||||
|
||||
if __name__ == "__main__":
|
||||
main ()
|
||||
|
@ -1,53 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2007-2010 iMatix Corporation
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
import sys
|
||||
import libpyzmq
|
||||
import time
|
||||
|
||||
def main ():
|
||||
if len (sys.argv) != 4:
|
||||
print 'usage: remote_thr <connect-to> <message-size> <message-count>'
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
connect_to = sys.argv [1]
|
||||
message_size = int (sys.argv [2])
|
||||
message_count = int (sys.argv [3])
|
||||
except (ValueError, OverflowError), e:
|
||||
print 'message-size and message-count must be integers'
|
||||
sys.exit (1)
|
||||
|
||||
ctx = libpyzmq.Context (1, 1);
|
||||
s = libpyzmq.Socket (ctx, libpyzmq.PUB)
|
||||
|
||||
# Add your socket options here.
|
||||
# For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
||||
|
||||
s.connect (connect_to)
|
||||
|
||||
msg = ''.join ([' ' for n in range (0, message_size)])
|
||||
|
||||
for i in range (0, message_count):
|
||||
s.send (msg)
|
||||
|
||||
time.sleep (10)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main ()
|
Loading…
x
Reference in New Issue
Block a user