Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement set/get for SO_RCVBUF #42

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions _sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ static PyObject* get_adaptation(PyObject* dummy, PyObject* args);
static PyObject* set_adaptation(PyObject* dummy, PyObject* args);
static PyObject* get_sndbuf(PyObject* dummy, PyObject* args);
static PyObject* set_sndbuf(PyObject* dummy, PyObject* args);
static PyObject* get_rcvbuf(PyObject* dummy, PyObject* args);
static PyObject* set_rcvbuf(PyObject* dummy, PyObject* args);
static PyObject* set_peer_primary(PyObject* dummy, PyObject* args);
static PyObject* set_primary(PyObject* dummy, PyObject* args);
static PyObject* bindx(PyObject* dummy, PyObject* args);
Expand Down Expand Up @@ -134,6 +136,8 @@ static PyMethodDef _sctp_methods[] =
{"set_adaptation", set_adaptation, METH_VARARGS, ""},
{"get_sndbuf", get_sndbuf, METH_VARARGS, ""},
{"set_sndbuf", set_sndbuf, METH_VARARGS, ""},
{"get_rcvbuf", get_rcvbuf, METH_VARARGS, ""},
{"set_rcvbuf", set_rcvbuf, METH_VARARGS, ""},
{"get_disable_fragments", get_disable_fragments, METH_VARARGS, ""},
{"set_disable_fragments", set_disable_fragments, METH_VARARGS, ""},
{"get_events", get_events, METH_VARARGS, ""},
Expand Down Expand Up @@ -1175,7 +1179,7 @@ static PyObject* get_sndbuf(PyObject* dummy, PyObject* args)
PyObject* ret = 0;
int fd, v;
socklen_t lv = sizeof(v);

if (PyArg_ParseTuple(args, "i", &fd)) {
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &v, &lv)) {
PyErr_SetFromErrno(PyExc_IOError);
Expand All @@ -1198,7 +1202,38 @@ static PyObject* set_sndbuf(PyObject* dummy, PyObject* args)
ret = Py_None; Py_INCREF(ret);
}
}
return ret;
return ret;
}

static PyObject* get_rcvbuf(PyObject* dummy, PyObject* args)
{
PyObject* ret = 0;
int fd, v;
socklen_t lv = sizeof(v);

if (PyArg_ParseTuple(args, "i", &fd)) {
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &v, &lv)) {
PyErr_SetFromErrno(PyExc_IOError);
} else {
ret = Py23_PyLong_FromLong(v);
}
}
return ret;
}

static PyObject* set_rcvbuf(PyObject* dummy, PyObject* args)
{
PyObject* ret = 0;
int fd, v;

if (PyArg_ParseTuple(args, "ii", &fd, &v)) {
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v))) {
PyErr_SetFromErrno(PyExc_IOError);
} else {
ret = Py_None; Py_INCREF(ret);
}
}
return ret;
}

static int to_sockaddr(const char *caddr, int port, struct sockaddr* saddr, int* slen)
Expand Down
15 changes: 14 additions & 1 deletion sctp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,14 +1382,27 @@ def get_sndbuf(self):
Gets the send buffer size from the kernel for this socket.
"""
return _sctp.get_sndbuf(self._sk.fileno())

def set_sndbuf(self, rvalue):
"""
Sets the send buffer size in the kernel for this socket.
"""
# Linux doubles the size, hence we divise it by 2
_sctp.set_sndbuf(self._sk.fileno(), rvalue//2)

def get_rcvbuf(self):
"""
Gets the receive buffer size from the kernel for this socket.
"""
return _sctp.get_rcvbuf(self._sk.fileno())

def set_rcvbuf(self, rvalue):
"""
Sets the receive buffer size in the kernel for this socket.
"""
# Linux doubles the size, hence we divise it by 2
_sctp.set_rcvbuf(self._sk.fileno(), rvalue//2)

def get_disable_fragments(self):
"""
Queries kernel and returns True if message fragmenting is disable for
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
from distutils.core import setup, Extension

setup(name='pysctp',
version='0.7.1',
version='0.7.2',
license = "LGPL",
description = 'pysctp is a python module for the SCTP protocol stack and library',
long_description = 'pysctp is a python wrapper for the SCTP protocol stack and library. On Mac OS X you will need the SCTP NKE (Kernel Extensions). On Linux systems, you need an SCTP-aware kernel (most are) and install the following packages (debian): apt install libsctp-dev libsctp1 lksctp-tools',
url = "https://github.com/p1sec/pysctp",
keywords = "SCTP SIGTRAN",
platforms = ["Linux", "Debian", "Ubuntu", "Mac OS X (untested)"],
platforms = ["Linux", "Debian", "Ubuntu", "Fedora", "Mac OS X (untested)"],
classifiers = ['Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
Expand Down