Avoid unnecessary timeout checks.

On the Apple II the timer_read function is actually a delay function. Therefore we want to avoid calling it if we're busy processing incoming data. Fortunately timer_read is only necessary to trigger a TCP keep alive message. But if we're busy processing incoming data then we for sure need no TCP keep alive. So we simply mark if we just processed incoming data and skip the timeout check.
This commit is contained in:
Oliver Schmidt 2017-05-21 22:39:10 +02:00
parent 7586cc1651
commit 29587a1ebe

View File

@ -166,22 +166,27 @@ telnet_main_entry:
lda #0 lda #0
sta connection_close_requested sta connection_close_requested
sta connection_closed sta connection_closed
sta data_received
sta iac_response_buffer_length sta iac_response_buffer_length
ldax #cursor_on ldax #cursor_on
jsr print_vt100 jsr print_vt100
@main_polling_loop: @main_polling_loop:
jsr timer_read jsr timer_read
txa txa ; 1/1000 * 256 = ~ 1/4 seconds
adc #$20 ; 32 x 1/4 = ~ 8 seconds adc #$20 ; 32 x 1/4 = ~ 8 seconds
sta telnet_timeout sta telnet_timeout
@wait_for_keypress: @check_timeout:
lda data_received
bne :+
jsr timer_read jsr timer_read
cpx telnet_timeout cpx telnet_timeout
bne :+ bne :+
jsr tcp_send_keep_alive jsr tcp_send_keep_alive
jmp @main_polling_loop jmp @main_polling_loop
: jsr ip65_process : lda #0
sta data_received
jsr ip65_process
lda connection_close_requested lda connection_close_requested
beq :+ beq :+
jsr tcp_close jsr tcp_close
@ -201,7 +206,7 @@ telnet_main_entry:
ldax #iac_response_buffer ldax #iac_response_buffer
jsr tcp_send jsr tcp_send
: jsr get_key_if_available : jsr get_key_if_available
beq @wait_for_keypress beq @check_timeout
ldx #0 ldx #0
stx tcp_send_data_len stx tcp_send_data_len
stx tcp_send_data_len+1 stx tcp_send_data_len+1
@ -286,18 +291,17 @@ send_char:
; tcp callback - will be executed whenever data arrives on the TCP connection ; tcp callback - will be executed whenever data arrives on the TCP connection
telnet_callback: telnet_callback:
lda tcp_inbound_data_length+1
cmp #$ff
bne :+
lda #1 lda #1
ldx tcp_inbound_data_length+1
cpx #$ff
bne :+
sta connection_closed sta connection_closed
rts rts
: ldax tcp_inbound_data_ptr : sta data_received
stax buffer_ptr
lda tcp_inbound_data_length lda tcp_inbound_data_length
sta buffer_length stax buffer_length
lda tcp_inbound_data_length+1 ldax tcp_inbound_data_ptr
sta buffer_length+1 stax buffer_ptr
@next_byte: @next_byte:
ldy #0 ldy #0
@ -527,6 +531,7 @@ telnet_port: .res 2 ; port number to connect to
telnet_timeout: .res 1 telnet_timeout: .res 1
connection_close_requested: .res 1 connection_close_requested: .res 1
connection_closed: .res 1 connection_closed: .res 1
data_received: .res 1
buffer_offset: .res 1 buffer_offset: .res 1
telnet_command: .res 1 telnet_command: .res 1
telnet_option: .res 1 telnet_option: .res 1