python: add Session.submit_ping()

This commit is contained in:
Tatsuhiro Tsujikawa 2012-08-22 01:49:02 +09:00
parent 7a362e23b3
commit 396d4a7fae
4 changed files with 46 additions and 1 deletions

View File

@ -426,6 +426,10 @@ Session objects
with the status code *status_code*. See `Stream Status Codes`_ for with the status code *status_code*. See `Stream Status Codes`_ for
available status codes. available status codes.
.. py:method:: Session.submit_ping()
Submits PING frame.
.. py:method:: Session.submit_goaway(status_code) .. py:method:: Session.submit_goaway(status_code)
Submits GOAWAY frame. The status code *status_code* is ignored if Submits GOAWAY frame. The status code *status_code* is ignored if

View File

@ -119,6 +119,10 @@ cdef extern from 'spdylay/spdylay.h':
size_t niv size_t niv
spdylay_settings_entry *iv spdylay_settings_entry *iv
ctypedef struct spdylay_ping:
spdylay_ctrl_hd hd
uint32_t unique_id
ctypedef struct spdylay_goaway: ctypedef struct spdylay_goaway:
spdylay_ctrl_hd hd spdylay_ctrl_hd hd
int32_t last_good_stream_id int32_t last_good_stream_id
@ -129,7 +133,7 @@ cdef extern from 'spdylay/spdylay.h':
spdylay_syn_reply syn_reply spdylay_syn_reply syn_reply
spdylay_rst_stream rst_stream spdylay_rst_stream rst_stream
spdylay_settings settings spdylay_settings settings
#spdylay_ping ping spdylay_ping ping
spdylay_goaway goaway spdylay_goaway goaway
spdylay_headers headers spdylay_headers headers
#spdylay_window_update window_update #spdylay_window_update window_update
@ -247,6 +251,8 @@ cdef extern from 'spdylay/spdylay.h':
int spdylay_submit_rst_stream(spdylay_session *session, int spdylay_submit_rst_stream(spdylay_session *session,
int32_t stream_id, uint32_t status_code) int32_t stream_id, uint32_t status_code)
int spdylay_submit_ping(spdylay_session *session)
int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code) int spdylay_submit_goaway(spdylay_session *session, uint32_t status_code)
int spdylay_submit_settings(spdylay_session *session, uint8_t flags, int spdylay_submit_settings(spdylay_session *session, uint8_t flags,

View File

@ -153,6 +153,18 @@ cdef class SettingsFrame(CtrlFrame):
def __get__(self): def __get__(self):
return self.iv return self.iv
cdef class PingFrame(CtrlFrame):
cdef uint32_t unique_id
cdef void fill(self, cspdylay.spdylay_ping *frame):
self.fillhd(&frame.hd)
self.unique_id = frame.unique_id
property unique_id:
def __get__(self):
return self.unique_id
cdef class GoawayFrame(CtrlFrame): cdef class GoawayFrame(CtrlFrame):
cdef int32_t last_good_stream_id cdef int32_t last_good_stream_id
cdef uint32_t status_code cdef uint32_t status_code
@ -239,6 +251,7 @@ cdef void on_ctrl_recv_callback(cspdylay.spdylay_session *session,
cdef HeadersFrame headers cdef HeadersFrame headers
cdef RstStreamFrame rst_stream cdef RstStreamFrame rst_stream
cdef SettingsFrame settings cdef SettingsFrame settings
cdef PingFrame ping
cdef GoawayFrame goaway cdef GoawayFrame goaway
cdef Session pysession = <Session>user_data cdef Session pysession = <Session>user_data
@ -267,6 +280,10 @@ cdef void on_ctrl_recv_callback(cspdylay.spdylay_session *session,
settings = SettingsFrame() settings = SettingsFrame()
settings.fill(&frame.settings) settings.fill(&frame.settings)
pyframe = settings pyframe = settings
elif frame_type == cspdylay.SPDYLAY_PING:
ping = PingFrame()
ping.fill(&frame.ping)
pyframe = ping
elif frame_type == cspdylay.SPDYLAY_GOAWAY: elif frame_type == cspdylay.SPDYLAY_GOAWAY:
goaway = GoawayFrame() goaway = GoawayFrame()
goaway.fill(&frame.goaway) goaway.fill(&frame.goaway)
@ -706,6 +723,14 @@ cdef class Session:
elif rv == cspdylay.SPDYLAY_ERR_NOMEM: elif rv == cspdylay.SPDYLAY_ERR_NOMEM:
raise MemoryError() raise MemoryError()
cpdef submit_ping(self):
cdef int rv
rv = cspdylay.spdylay_submit_ping(self._c_session)
if rv == 0:
return
elif rv == cspdylay.SPDYLAY_ERR_NOMEM:
raise MemoryError()
cpdef submit_goaway(self, status_code): cpdef submit_goaway(self, status_code):
cdef int rv cdef int rv
rv = cspdylay.spdylay_submit_goaway(self._c_session, status_code) rv = cspdylay.spdylay_submit_goaway(self._c_session, status_code)

View File

@ -304,5 +304,15 @@ class SpdylayTests(unittest.TestCase):
self.assertEqual(1, frame.stream_id) self.assertEqual(1, frame.stream_id)
self.assertEqual((b':host', b'localhost'), frame.nv[0]) self.assertEqual((b':host', b'localhost'), frame.nv[0])
def test_submit_ping(self):
self.client_session.submit_ping()
self.client_session.send()
self.server_session.recv()
self.assertEqual(1, len(self.server_streams.recv_frames))
frame = self.server_streams.recv_frames[0]
self.assertEqual(spdylay.PING, frame.frame_type)
self.assertEqual(1, frame.unique_id)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()