/*
- * Definition of a `Connection` type.
+ * Definition of a `Connection` type.
* Used by `socket_connection.c` and `pipe_connection.c`.
*
* connection.h
static char *kwlist[] = {"handle", "readable", "writable", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, F_HANDLE "|ii", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, F_HANDLE "|ii", kwlist,
&handle, &readable, &writable))
return NULL;
}
if (!readable && !writable) {
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_ValueError,
"either readable or writable must be true");
return NULL;
}
} else {
if (size < 0) {
PyErr_SetString(PyExc_ValueError, "size is negative");
- return NULL;
+ return NULL;
}
if (offset + size > length) {
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_ValueError,
"buffer length < offset + size");
return NULL;
}
}
static PyObject *
-connection_recvbytes(ConnectionObject *self, PyObject *args)
+connection_recvbytes(ConnectionObject *self, PyObject *args)
{
char *freeme = NULL;
Py_ssize_t res, maxlength = PY_SSIZE_T_MAX;
return NULL;
CHECK_READABLE(self);
-
+
if (maxlength < 0) {
PyErr_SetString(PyExc_ValueError, "maxlength < 0");
return NULL;
}
-
- res = conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
+
+ res = conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
&freeme, maxlength);
-
+
if (res < 0) {
if (res == MP_BAD_MESSAGE_LENGTH) {
if ((self->flags & WRITABLE) == 0) {
}
}
mp_SetError(PyExc_IOError, res);
- } else {
+ } else {
if (freeme == NULL) {
result = PyString_FromStringAndSize(self->buffer, res);
} else {
PyMem_Free(freeme);
}
}
-
+
return result;
}
static PyObject *
-connection_recvbytes_into(ConnectionObject *self, PyObject *args)
+connection_recvbytes_into(ConnectionObject *self, PyObject *args)
{
char *freeme = NULL, *buffer = NULL;
Py_ssize_t res, length, offset = 0;
Py_buffer pbuf;
CHECK_READABLE(self);
-
- if (!PyArg_ParseTuple(args, "w*|" F_PY_SSIZE_T,
+
+ if (!PyArg_ParseTuple(args, "w*|" F_PY_SSIZE_T,
&pbuf, &offset))
return NULL;
if (offset < 0) {
PyErr_SetString(PyExc_ValueError, "negative offset");
goto _error;
- }
+ }
if (offset > length) {
PyErr_SetString(PyExc_ValueError, "offset too large");
goto _error;
}
- res = conn_recv_string(self, buffer+offset, length-offset,
+ res = conn_recv_string(self, buffer+offset, length-offset,
&freeme, PY_SSIZE_T_MAX);
if (res < 0) {
if (freeme == NULL) {
result = PyInt_FromSsize_t(res);
} else {
- result = PyObject_CallFunction(BufferTooShort,
- F_RBUFFER "#",
+ result = PyObject_CallFunction(BufferTooShort,
+ F_RBUFFER "#",
freeme, res);
PyMem_Free(freeme);
if (result) {
CHECK_WRITABLE(self);
- pickled_string = PyObject_CallFunctionObjArgs(pickle_dumps, obj,
+ pickled_string = PyObject_CallFunctionObjArgs(pickle_dumps, obj,
pickle_protocol, NULL);
if (!pickled_string)
goto failure;
CHECK_READABLE(self);
- res = conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
+ res = conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
&freeme, PY_SSIZE_T_MAX);
if (res < 0) {
}
}
mp_SetError(PyExc_IOError, res);
- } else {
+ } else {
if (freeme == NULL) {
temp = PyString_FromStringAndSize(self->buffer, res);
} else {
}
if (temp)
- result = PyObject_CallFunctionObjArgs(pickle_loads,
+ result = PyObject_CallFunctionObjArgs(pickle_loads,
temp, NULL);
Py_XDECREF(temp);
return result;
static char *conn_type[] = {"read-only", "write-only", "read-write"};
assert(self->flags >= 1 && self->flags <= 3);
- return FROM_FORMAT("<%s %s, handle %zd>",
+ return FROM_FORMAT("<%s %s, handle %zd>",
conn_type[self->flags - 1],
CONNECTION_NAME, (Py_ssize_t)self->handle);
}
*/
static PyMethodDef connection_methods[] = {
- {"send_bytes", (PyCFunction)connection_sendbytes, METH_VARARGS,
+ {"send_bytes", (PyCFunction)connection_sendbytes, METH_VARARGS,
"send the byte data from a readable buffer-like object"},
- {"recv_bytes", (PyCFunction)connection_recvbytes, METH_VARARGS,
+ {"recv_bytes", (PyCFunction)connection_recvbytes, METH_VARARGS,
"receive byte data as a string"},
{"recv_bytes_into",(PyCFunction)connection_recvbytes_into,METH_VARARGS,
"receive byte data into a writeable buffer-like object\n"
"returns the number of bytes read"},
- {"send", (PyCFunction)connection_send_obj, METH_O,
+ {"send", (PyCFunction)connection_send_obj, METH_O,
"send a (picklable) object"},
- {"recv", (PyCFunction)connection_recv_obj, METH_NOARGS,
+ {"recv", (PyCFunction)connection_recv_obj, METH_NOARGS,
"receive a (picklable) object"},
- {"poll", (PyCFunction)connection_poll, METH_VARARGS,
+ {"poll", (PyCFunction)connection_poll, METH_VARARGS,
"whether there is any input available to be read"},
{"fileno", (PyCFunction)connection_fileno, METH_NOARGS,
"file descriptor or handle of the connection"},
};
static PyGetSetDef connection_getset[] = {
- {"closed", (getter)connection_closed, NULL,
+ {"closed", (getter)connection_closed, NULL,
"True if the connection is closed", NULL},
- {"readable", (getter)connection_readable, NULL,
+ {"readable", (getter)connection_readable, NULL,
"True if the connection is readable", NULL},
- {"writable", (getter)connection_writable, NULL,
+ {"writable", (getter)connection_writable, NULL,
"True if the connection is writable", NULL},
{NULL}
};
/* tp_getattro */ 0,
/* tp_setattro */ 0,
/* tp_as_buffer */ 0,
- /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_WEAKREFS,
/* tp_doc */ connection_doc,
/* tp_traverse */ 0,
return NULL;
Py_BEGIN_ALLOW_THREADS
- success = CloseHandle(hObject);
+ success = CloseHandle(hObject);
Py_END_ALLOW_THREADS
if (!success)
LPOVERLAPPED lpOverlapped;
BOOL success;
- if (!PyArg_ParseTuple(args, F_HANDLE F_POINTER,
+ if (!PyArg_ParseTuple(args, F_HANDLE F_POINTER,
&hNamedPipe, &lpOverlapped))
return NULL;
HANDLE hTemplateFile;
HANDLE handle;
- if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_POINTER
+ if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_POINTER
F_DWORD F_DWORD F_HANDLE,
- &lpFileName, &dwDesiredAccess, &dwShareMode,
- &lpSecurityAttributes, &dwCreationDisposition,
+ &lpFileName, &dwDesiredAccess, &dwShareMode,
+ &lpSecurityAttributes, &dwCreationDisposition,
&dwFlagsAndAttributes, &hTemplateFile))
return NULL;
Py_BEGIN_ALLOW_THREADS
- handle = CreateFile(lpFileName, dwDesiredAccess,
- dwShareMode, lpSecurityAttributes,
- dwCreationDisposition,
+ handle = CreateFile(lpFileName, dwDesiredAccess,
+ dwShareMode, lpSecurityAttributes,
+ dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
Py_END_ALLOW_THREADS
LPSECURITY_ATTRIBUTES lpSecurityAttributes;
HANDLE handle;
- if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_DWORD
+ if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_DWORD
F_DWORD F_DWORD F_DWORD F_POINTER,
- &lpName, &dwOpenMode, &dwPipeMode,
- &nMaxInstances, &nOutBufferSize,
+ &lpName, &dwOpenMode, &dwPipeMode,
+ &nMaxInstances, &nOutBufferSize,
&nInBufferSize, &nDefaultTimeOut,
&lpSecurityAttributes))
return NULL;
Py_BEGIN_ALLOW_THREADS
- handle = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode,
- nMaxInstances, nOutBufferSize,
+ handle = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode,
+ nMaxInstances, nOutBufferSize,
nInBufferSize, nDefaultTimeOut,
lpSecurityAttributes);
Py_END_ALLOW_THREADS
DWORD dwProcessId;
HANDLE handle;
- if (!PyArg_ParseTuple(args, F_DWORD "i" F_DWORD,
+ if (!PyArg_ParseTuple(args, F_DWORD "i" F_DWORD,
&dwDesiredAccess, &bInheritHandle, &dwProcessId))
return NULL;
- handle = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
+ handle = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
if (handle == NULL)
return PyErr_SetFromWindowsErr(0);
DWORD dwArgs[3], *pArgs[3] = {NULL, NULL, NULL};
int i;
- if (!PyArg_ParseTuple(args, F_HANDLE "OOO",
+ if (!PyArg_ParseTuple(args, F_HANDLE "OOO",
&hNamedPipe, &oArgs[0], &oArgs[1], &oArgs[2]))
return NULL;