server: Use a sync timeout only on HTTP2.
This commit is contained in:
parent
fb5a889cca
commit
99ca1b50ce
2 changed files with 8 additions and 6 deletions
8
main.py
8
main.py
|
@ -340,14 +340,12 @@ def finalize_connection(server):
|
||||||
if negotiated_protocol is None:
|
if negotiated_protocol is None:
|
||||||
negotiated_protocol = server.socket.selected_npn_protocol()
|
negotiated_protocol = server.socket.selected_npn_protocol()
|
||||||
|
|
||||||
transport_type = None
|
|
||||||
|
|
||||||
if negotiated_protocol == "http/1.1":
|
if negotiated_protocol == "http/1.1":
|
||||||
transport_type = TransportType.HTTP
|
server.transport_type = TransportType.HTTP
|
||||||
elif negotiated_protocol == "h2":
|
elif negotiated_protocol == "h2":
|
||||||
transport_type = TransportType.HTTP2
|
server.transport_type = TransportType.HTTP2
|
||||||
|
|
||||||
data = server.client.connect(transport_type)
|
data = server.client.connect(server.transport_type)
|
||||||
server.send(data)
|
server.send(data)
|
||||||
|
|
||||||
server.login()
|
server.login()
|
||||||
|
|
|
@ -30,6 +30,7 @@ from nio import (
|
||||||
SyncRepsponse,
|
SyncRepsponse,
|
||||||
RoomSendResponse,
|
RoomSendResponse,
|
||||||
TransportResponse,
|
TransportResponse,
|
||||||
|
TransportType,
|
||||||
LocalProtocolError
|
LocalProtocolError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -173,6 +174,7 @@ class MatrixServer(object):
|
||||||
self.sync_time = None # type: Optional[float]
|
self.sync_time = None # type: Optional[float]
|
||||||
self.socket = None # type: ssl.SSLSocket
|
self.socket = None # type: ssl.SSLSocket
|
||||||
self.ssl_context = ssl.create_default_context() # type: ssl.SSLContext
|
self.ssl_context = ssl.create_default_context() # type: ssl.SSLContext
|
||||||
|
self.transport_type = None # type: Optional[nio.TransportType]
|
||||||
|
|
||||||
# Enable http2 negotiation on the ssl context.
|
# Enable http2 negotiation on the ssl context.
|
||||||
self.ssl_context.set_alpn_protocols(["h2", "http/1.1"])
|
self.ssl_context.set_alpn_protocols(["h2", "http/1.1"])
|
||||||
|
@ -391,6 +393,7 @@ class MatrixServer(object):
|
||||||
|
|
||||||
self.send_buffer = b""
|
self.send_buffer = b""
|
||||||
self.current_message = None
|
self.current_message = None
|
||||||
|
self.transport_type = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.disconnect()
|
self.client.disconnect()
|
||||||
|
@ -702,7 +705,8 @@ def matrix_timer_cb(server_name, remaining_calls):
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
if server.sync_time and current_time > (server.sync_time + 2):
|
if server.sync_time and current_time > (server.sync_time + 2):
|
||||||
server.sync(30000)
|
timeout = 0 if server.transport_type == TransportType.HTTP else 30000
|
||||||
|
server.sync(timeout)
|
||||||
|
|
||||||
while server.send_queue:
|
while server.send_queue:
|
||||||
message = server.send_queue.popleft()
|
message = server.send_queue.popleft()
|
||||||
|
|
Loading…
Add table
Reference in a new issue