STM32 Experiment & Note —— (011) Linux TCP (Not translated)
»
(001) HAL Library LED Lighting
(002) HAL Library LCD Frame Animation
(003) HAL Library FFT Dynamic Spectrum
(004) HAL Library FFT Speed Up
(005) HAL Library Understanding DMA
(006) Watchdog Summary
(007) GPIO Usage Steps
(008) CubeIDE Implementation of USB Peripherals*
(009) Why C99
(010) Linux UDP
(011) Linux TCP
(012) Temperature Control of Arm
(013) OpenWrt cross-compilation
(014) Basic data type in C99
(015) C99 struct
(016) C99 enum
(017) C99 funciont and L-Value, R-Value
(018) C99 pointer*
(019) C99 With only value assignment*
(020) C99 array with space, pointer with no space
(021) C99 No template function
(022) POSIX pthread multi-threads mutex*
(023) POSIX pthread multi-threads programming*
(024) C99 if
(025) C99 switch
(026) C99 loop
(027) C99 time and wait*
(028) High-precision calculation with GMP*
(029) Web Service Lib*
(030) International Components for Unicode (ICU)*
(031) Performance of C is higher than C++, because...*
(032) C99 weak function
(033) MTU TCP SOCKET
(034) STM32 UART Continually Sending Data
(035) STM32 UART Continually Receiving Data
(037) STM32 Normal and Circle
(038) STM32 UART clear transfer error flag
(039) STM32 UART Idle Callback
(040) STM32 UART, RS232 single TX line
(041) STM32 RS485 Differential signal communication
(042) STM32 HAL DMA Poll For Transfer
(043) STM32 enter low power comsuption mode
(044) STM32 Clear Flag of TCx in DMA IRQ
(045) STM32软件函数命名规范
(046) Deal with Idle in xxxCpltCallback
(047) C99 Built in macros
(048) isr enabled after calling ***_IT
(049) Procedure of starting STM32
(050) Load new firmware online
(051) SCB->VTOR
(052) STM32 Address space in programme
(053) STM32 Move program to other space
(054) STM32 Bootloader
(055) Keil中的下载算法
(056)编译器优化出错点
🍓(001) Close Swapfile
🍓(002) Format USB disk to ext4 with 1k blocks
🍓(003) Query Linux Version info and CPU info
🍓(004) Speed up latest version of Ubuntu
🍓(005) Clone 360 Browser Core Source Code Script
🍓(006) Before run Firefox in Ubuntu24.04
🍓(007) MAC Address
🍓(008) RMII & PHY
🍓(009) Ubuntu Server firewall configuration
🍓(010) Linux yield cpu by code
🍓(011) Linux Hardware Concept
🍓(012) Linux Inter-Process Communication
🍓(013) Ban Git force push
🍓(014) Ban Git reset --hard
🍓(015) Save unsaved cache to disk immedutely
🍓(016) 拷贝pre-receive到每个git仓库的脚本
🍓(017) sshd密码输入错误禁用IP3分钟
🖥️(001) 异机备份低功耗自用Git服务器搭建
🖥️(002) OpenWRT配置注意事项
🕹️(001) while(1){} cpu reentered
🕹️(002) functions for multi-thread in FreeRTOS
🕹️(003) FreeRTOS critical code zone
🕹️(004) FreeRTOS fix NULL not defined error
🕹️(005) lowest priority interrupt of ARM: PENDSV
🕹️(006) Configuration of tasks priority levels
🕹️(006) Cautions of different priority tasks locked
🕹️(008) Close scheduling of same priority tasks
🕹️(009) OTA Technology
🕹️(010) FreeRTOS create static task
🕹️(011) FreeRTOS list task list
🕹️(012) FreeRTOS HeapSize statistics
🕹️(013) FreeRTOS xTaskGetHandle
🕹️(014) FreeRTOS common method of create tasks
🕹️(015) FreeRTOS fix problem of tasks locked
🕹️(016) FreeRTOS Superest interrupt: SVC
🕹️(017) FreeRTOS interrupt call in privilege mode
🕹️(018) FreeRTOS SVC enter user mode
🕹️(019) FreeRTOS delay util
🕹️(020) FreeRTOS low consumption by Tickless
🕹️(021) FreeRTOS IdleHook
🕹️(022) FreeRTOS Hooks
🕹️(023) FreeRTOS yield CPU by code
🕹️(024) FreeRTOS semaphore
🕹️(025) FreeRTOS resolve priority inversion
🕹️(026) FreeRTOS get task priority
🕹️(027) FreeRTOS set task priority
🕹️(028) FreeRTOS function prefix
🕹️(029) Don't call RTOS function in IRQ handle
🕹️(030) Bottom half operation decrease semaphore
🕹️(031) Support Suspending for ever
🕹️(032) Call FreeRTOS SysCall in ISR
🕹️(033) Principle of Top Half and bottom haf
🕹️(034) FATFS in STM32 support exFat
🕹️(035) Message Queue in FreeRTOS
🕹️(036) Timer Tasks in FreeRTOS
🕹️(037) Reason of can not ping board
🕹️(038) LwIP Tcp Server Sample Code
🕹️(039) mutex equals binarySempahore
🕹️(040) Relationship between MEMP and Pbuf
🕹️(041) FreeRTOS连接ESP WiFi(待完成)
📟(001)CMSIS标准学习
🕹️(001)函数调用被优化
    非阻塞SOCKET的实现要点只有一个:要在SOCKET连接建立后,再设置非阻塞,而非一开始就设置非阻塞。如果一开始就设置非阻塞,之后再去连接,则SOCKET没法建立。

    ***************************************************************************************************
    创建socket,TCP(SOCK_STREAM)/IP(IPPROTO_IP)函数:sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 创建失败:sock_fd < 0
    设置socket连接特性函数(设置TCP_NODELAY为1,立即发送数据):setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &trueVal, sizeof(trueVal)); 调用失败:返回值 < 0
    设置socket连接特性函数(设置SO_KEEPALIVE为1,触发保活机制,可用配置项:TCP_KEEPIDLE、TCP_KEEPINTVL、TCP_KEEPCNT):setsockopt(sock_fd, SOL_SOCKET, SO_KEEPALIVE, &trueVal, sizeof(trueVal))); 调用失败:返回值 < 0
    设置socket连接特性函数(设置SO_NOSIGPIPE为1,在BSD, MacOSX系统上关闭SIGPIPE,防止写入已经关闭的fd时程序被挂起):setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &trueVal, sizeof(trueVal)); 调用失败:返回值 < 0
    =============================================================================
    设置socket连接特性函数(设置SOCKET关闭时的特性SO_linger):
    struct linger so_linger;
    so_linger.l_nooff = TRUE;
    so_linger.l_linger = 30;
    setsockopt(sock_fd, SOL_SOCKET,SO_LINGER,&so_linger,sizeof(so_linger));
    =============================================================================
    TRUE,30,只要so_linger为on并且等待时间大于0(单位:秒),则close时将始终阻塞等待 l_linger 秒 时间
    如果在等待过程中,TCP模块成功发送完残留缓冲区的数据,则close返回0表示成功
    如果未能成功发送完成,则close返回-1,并将errno设置为EWOULDBLOCK
    =============================================================================
    如果so_linger设置为off,则close时会立即返回
    如果close返回为0则表示成功
    如果返回为-1,则errno中为错误原因
    =============================================================================


    ***************************************************************************************************
    sockaddr_in(socket address ip number)结构体的用法:
    struct sockaddr_in server_addr;
    memset((void*)&server_addr,0,sizeof(server_addr));
    server_addr.sin_family=AF_INET;                            //IP地址为IPv4
    server_addr.sin_addr.s_addr=inet_addr(server_ip);  //服务器端IP地址,server_ip为const char*
    server_addr.sin_port=htons(server_port);                //服务器端端口,server_port为int
    其中,struct sockaddr_in结构体中的server_addr.sin_zero为IPv6数据留白
    连接到目标服务器:connect(sock_fd, (struct sockaddr*)&server_addr, sizeof(server_addr));调用失败:返回值 < 0
    ***************************************************************************************************

    连接建立后,设置非阻塞模式(如果先设置非阻塞后连接,则无法建立连接):
    flags = fcntl(sock_fd, F_GETFL);
    if (flags == -1 || fcntl(sock_fd, F_SETFL, (long)(flags | O_NONBLOCK)) == -1) {
        printf("Socket Error: Set O_NONBLOCK error\n");
        goto err;
    }
    ***************************************************************************************************    
    关闭socket连接:close(sock_fd);

    在socket的设置中还有两个很有用的设置项,那就是用于IP穿透的SO_REUSEADDR和SO_REUSEPORT,也就是当以客户端方式建立连接后,再重用此地址和端口建立Server服务,以方便穿透的连接请求进入当前服务。
    当然,SO_REUSEADDR还用在服务器程序的监听程序的进程重启而用于服务的子进程不中断的重启服务过程。
«
--Alex.Zhang
--www.v-signon.com Learningers Co-Encouraged
Back
Personal Art: www.up-task.com Unit: Individual
中文 Русский 京ICP备19038994号-2
If the content on this website infringes upon your any rights, please contact me at 1307776259@qq.com for removal