Lines Matching full:tcp
1 /* tcp.c - TCP specific code for echo server */
75 data->tcp.sock = socket(bind_addr->sa_family, SOCK_STREAM, in start_tcp_proto()
78 data->tcp.sock = socket(bind_addr->sa_family, SOCK_STREAM, in start_tcp_proto()
81 if (data->tcp.sock < 0) { in start_tcp_proto()
82 LOG_ERR("Failed to create TCP socket (%s): %d", data->proto, in start_tcp_proto()
95 ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_SEC_TAG_LIST, in start_tcp_proto()
98 LOG_ERR("Failed to set TCP secure option (%s): %d", data->proto, in start_tcp_proto()
107 (void)setsockopt(data->tcp.sock, IPPROTO_IPV6, in start_tcp_proto()
116 (void)setsockopt(data->tcp.sock, IPPROTO_IPV6, IPV6_V6ONLY, in start_tcp_proto()
120 ret = bind(data->tcp.sock, bind_addr, bind_addrlen); in start_tcp_proto()
122 LOG_ERR("Failed to bind TCP socket (%s): %d", data->proto, in start_tcp_proto()
127 ret = listen(data->tcp.sock, MAX_CLIENT_QUEUE); in start_tcp_proto()
129 LOG_ERR("Failed to listen on TCP socket (%s): %d", in start_tcp_proto()
147 client = data->tcp.accepted[slot].sock; in handle_data()
151 data->tcp.accepted[slot].recv_buffer + offset, in handle_data()
152 sizeof(data->tcp.accepted[slot].recv_buffer) - offset, in handle_data()
157 LOG_INF("TCP (%s): Connection closed", data->proto); in handle_data()
161 LOG_ERR("TCP (%s): Connection error %d", data->proto, in handle_data()
165 atomic_add(&data->tcp.bytes_received, received); in handle_data()
174 if (offset == sizeof(data->tcp.accepted[slot].recv_buffer) || in handle_data()
176 data->tcp.accepted[slot].recv_buffer + offset, in handle_data()
177 sizeof(data->tcp.accepted[slot].recv_buffer) - in handle_data()
183 data->tcp.accepted[slot].recv_buffer, in handle_data()
186 LOG_ERR("TCP (%s): Failed to send, " in handle_data()
191 LOG_DBG("TCP (%s): Received and replied with %d bytes", in handle_data()
194 if (++data->tcp.accepted[slot].counter % 1000 == 0U) { in handle_data()
195 LOG_INF("%s TCP: Sent %u packets", data->proto, in handle_data()
196 data->tcp.accepted[slot].counter); in handle_data()
209 data->tcp.accepted[slot].sock = -1; in handle_data()
217 if (data->tcp.accepted[i].sock < 0) { in get_free_slot()
232 LOG_INF("Waiting for TCP connection on port %d (%s)...", in process_tcp()
235 client = accept(data->tcp.sock, (struct sockaddr *)&client_addr, in process_tcp()
249 data->tcp.accepted[slot].sock = client; in process_tcp()
251 LOG_INF("TCP (%s): Accepted connection", data->proto); in process_tcp()
361 struct data *data = CONTAINER_OF(dwork, struct data, tcp.stats_print); in print_stats()
362 int total_received = atomic_get(&data->tcp.bytes_received); in print_stats()
366 LOG_INF("%s TCP: Received %d B/sec", data->proto, in print_stats()
369 LOG_INF("%s TCP: Received %d KiB/sec", data->proto, in print_stats()
373 atomic_set(&data->tcp.bytes_received, 0); in print_stats()
376 k_work_reschedule(&data->tcp.stats_print, K_SECONDS(STATS_TIMER)); in print_stats()
384 conf.ipv6.tcp.accepted[i].sock = -1; in start_tcp()
385 conf.ipv4.tcp.accepted[i].sock = -1; in start_tcp()
405 k_work_init_delayable(&conf.ipv6.tcp.stats_print, print_stats); in start_tcp()
407 k_work_reschedule(&conf.ipv6.tcp.stats_print, K_SECONDS(STATS_TIMER)); in start_tcp()
420 k_work_init_delayable(&conf.ipv4.tcp.stats_print, print_stats); in start_tcp()
422 k_work_reschedule(&conf.ipv4.tcp.stats_print, K_SECONDS(STATS_TIMER)); in start_tcp()
436 if (conf.ipv6.tcp.sock >= 0) { in stop_tcp()
437 (void)close(conf.ipv6.tcp.sock); in stop_tcp()
446 if (conf.ipv6.tcp.accepted[i].sock >= 0) { in stop_tcp()
447 (void)close(conf.ipv6.tcp.accepted[i].sock); in stop_tcp()
454 if (conf.ipv4.tcp.sock >= 0) { in stop_tcp()
455 (void)close(conf.ipv4.tcp.sock); in stop_tcp()
464 if (conf.ipv4.tcp.accepted[i].sock >= 0) { in stop_tcp()
465 (void)close(conf.ipv4.tcp.accepted[i].sock); in stop_tcp()