Fix issues with TX slots in src/sock.c
Fix issues with TX slots in src/sock.c wherein packets saved for resend would not be able to be resent, as their total length was not encoded properly into the slot structure
This commit is contained in:
		
							parent
							
								
									10432c9709
								
							
						
					
					
						commit
						2db5a0d0b9
					
				
					 1 changed files with 22 additions and 2 deletions
				
			
		
							
								
								
									
										24
									
								
								src/sock.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/sock.c
									
										
									
									
									
								
							|  | @ -66,7 +66,21 @@ static inline void *tx_slot(patty_ax25_sock *sock, size_t seq) { | ||||||
|     return (uint8_t *)sock->tx_slots + (i * tx_slot_size(sock)); |     return (uint8_t *)sock->tx_slots + (i * tx_slot_size(sock)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static inline void tx_slot_save_len(patty_ax25_sock *sock, | ||||||
|  |                                     size_t seq, | ||||||
|  |                                     size_t len) { | ||||||
|  |     size_t *size = (size_t *)tx_slot(sock, seq); | ||||||
|  | 
 | ||||||
|  |     *size = len; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static inline void *tx_slot_buf(patty_ax25_sock *sock, size_t seq) { | ||||||
|  |     return (uint8_t *)tx_slot(sock, seq) + sizeof(size_t); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int init_bufs(patty_ax25_sock *sock) { | static int init_bufs(patty_ax25_sock *sock) { | ||||||
|  |     size_t i; | ||||||
|  | 
 | ||||||
|     if ((sock->tx_buf = realloc(sock->tx_buf, tx_bufsz(sock))) == NULL) { |     if ((sock->tx_buf = realloc(sock->tx_buf, tx_bufsz(sock))) == NULL) { | ||||||
|         goto error_realloc_tx_buf; |         goto error_realloc_tx_buf; | ||||||
|     } |     } | ||||||
|  | @ -79,6 +93,10 @@ static int init_bufs(patty_ax25_sock *sock) { | ||||||
|         goto error_realloc_tx_slots; |         goto error_realloc_tx_slots; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     for (i=0; i<sock->n_window_tx; i++) { | ||||||
|  |         tx_slot_save_len(sock, i, 0); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return 0; |     return 0; | ||||||
| 
 | 
 | ||||||
| error_realloc_tx_slots: | error_realloc_tx_slots: | ||||||
|  | @ -380,7 +398,7 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, | ||||||
|     ssize_t encoded; |     ssize_t encoded; | ||||||
| 
 | 
 | ||||||
|     uint8_t *buf = PATTY_AX25_FRAME_CONTROL_I(control)? |     uint8_t *buf = PATTY_AX25_FRAME_CONTROL_I(control)? | ||||||
|         tx_slot(sock, sock->seq_send): sock->tx_buf; |         tx_slot_buf(sock, sock->seq_send): sock->tx_buf; | ||||||
| 
 | 
 | ||||||
|     if (sock->iface == NULL) { |     if (sock->iface == NULL) { | ||||||
|         errno = ENETDOWN; |         errno = ENETDOWN; | ||||||
|  | @ -418,6 +436,8 @@ ssize_t patty_ax25_sock_send(patty_ax25_sock *sock, | ||||||
|         memcpy(buf + offset, info, infolen); |         memcpy(buf + offset, info, infolen); | ||||||
| 
 | 
 | ||||||
|         offset += infolen; |         offset += infolen; | ||||||
|  | 
 | ||||||
|  |         tx_slot_save_len(sock, sock->seq_send, offset); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return patty_ax25_if_send(sock->iface, buf, offset); |     return patty_ax25_if_send(sock->iface, buf, offset); | ||||||
|  | @ -436,7 +456,7 @@ ssize_t patty_ax25_sock_resend(patty_ax25_sock *sock, | ||||||
| 
 | 
 | ||||||
|     size_t len = *((size_t *)slot); |     size_t len = *((size_t *)slot); | ||||||
| 
 | 
 | ||||||
|     return patty_ax25_if_send(sock->iface, buf, len); |     return len > 0? patty_ax25_if_send(sock->iface, buf, len): 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static uint16_t control_i(patty_ax25_sock *sock, int flag) { | static uint16_t control_i(patty_ax25_sock *sock, int flag) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue