|
|
@ -42,30 +42,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
static int pygrpc_server_init(Server *self, PyObject *args, PyObject *kwds) { |
|
|
|
static int pygrpc_server_init(Server *self, PyObject *args, PyObject *kwds) { |
|
|
|
const PyObject *completion_queue; |
|
|
|
const PyObject *completion_queue; |
|
|
|
PyObject *server_credentials; |
|
|
|
static char *kwlist[] = {"completion_queue", NULL}; |
|
|
|
static char *kwlist[] = {"completion_queue", "server_credentials", NULL}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O:Server", kwlist, |
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!:Server", kwlist, |
|
|
|
&pygrpc_CompletionQueueType, |
|
|
|
&pygrpc_CompletionQueueType, |
|
|
|
&completion_queue, &server_credentials)) { |
|
|
|
&completion_queue)) { |
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (server_credentials == Py_None) { |
|
|
|
|
|
|
|
self->c_server = grpc_server_create( |
|
|
|
|
|
|
|
((CompletionQueue *)completion_queue)->c_completion_queue, NULL); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} else if (PyObject_TypeCheck(server_credentials, |
|
|
|
|
|
|
|
&pygrpc_ServerCredentialsType)) { |
|
|
|
|
|
|
|
self->c_server = grpc_secure_server_create( |
|
|
|
|
|
|
|
((ServerCredentials *)server_credentials)->c_server_credentials, |
|
|
|
|
|
|
|
((CompletionQueue *)completion_queue)->c_completion_queue, NULL); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
PyErr_Format(PyExc_TypeError, |
|
|
|
|
|
|
|
"server_credentials must be _grpc.ServerCredentials, not %s", |
|
|
|
|
|
|
|
Py_TYPE(server_credentials)->tp_name); |
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self->c_server = grpc_server_create( |
|
|
|
|
|
|
|
((CompletionQueue *)completion_queue)->c_completion_queue, NULL); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void pygrpc_server_dealloc(Server *self) { |
|
|
|
static void pygrpc_server_dealloc(Server *self) { |
|
|
@ -92,13 +78,21 @@ static PyObject *pygrpc_server_add_http2_addr(Server *self, PyObject *args) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static PyObject *pygrpc_server_add_secure_http2_addr(Server *self, |
|
|
|
static PyObject *pygrpc_server_add_secure_http2_addr(Server *self, |
|
|
|
PyObject *args) { |
|
|
|
PyObject *args, |
|
|
|
|
|
|
|
PyObject *kwargs) { |
|
|
|
const char *addr; |
|
|
|
const char *addr; |
|
|
|
|
|
|
|
PyObject *server_credentials; |
|
|
|
|
|
|
|
static char *kwlist[] = {"addr", "server_credentials", NULL}; |
|
|
|
int port; |
|
|
|
int port; |
|
|
|
if (!PyArg_ParseTuple(args, "s:add_secure_http2_addr", &addr)) { |
|
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!:add_secure_http2_addr", |
|
|
|
|
|
|
|
kwlist, &addr, &pygrpc_ServerCredentialsType, |
|
|
|
|
|
|
|
&server_credentials)) { |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
port = grpc_server_add_secure_http2_port(self->c_server, addr); |
|
|
|
port = grpc_server_add_secure_http2_port( |
|
|
|
|
|
|
|
self->c_server, addr, |
|
|
|
|
|
|
|
((ServerCredentials *)server_credentials)->c_server_credentials); |
|
|
|
if (port == 0) { |
|
|
|
if (port == 0) { |
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Couldn't add port to server!"); |
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Couldn't add port to server!"); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
@ -138,8 +132,7 @@ static PyMethodDef methods[] = { |
|
|
|
METH_VARARGS, "Add a secure HTTP2 address."}, |
|
|
|
METH_VARARGS, "Add a secure HTTP2 address."}, |
|
|
|
{"start", (PyCFunction)pygrpc_server_start, METH_NOARGS, |
|
|
|
{"start", (PyCFunction)pygrpc_server_start, METH_NOARGS, |
|
|
|
"Starts the server."}, |
|
|
|
"Starts the server."}, |
|
|
|
{"service", (PyCFunction)pygrpc_server_service, METH_O, |
|
|
|
{"service", (PyCFunction)pygrpc_server_service, METH_O, "Services a call."}, |
|
|
|
"Services a call."}, |
|
|
|
|
|
|
|
{"stop", (PyCFunction)pygrpc_server_stop, METH_NOARGS, "Stops the server."}, |
|
|
|
{"stop", (PyCFunction)pygrpc_server_stop, METH_NOARGS, "Stops the server."}, |
|
|
|
{NULL}}; |
|
|
|
{NULL}}; |
|
|
|
|
|
|
|
|
|
|
|