recv

RTT学习之SPI设备

最后都变了- 提交于 2019-12-03 13:13:52
SPI 分为主、从、设备;具体又分标准SPI/DUAL SPI/QUAD SPI(用80字节的RAM rt_err_t rt_spi_take_bus(struct rt_spi_device *device); 代替收发寄存器) 从设备的操作:在多线程通讯中,从机需要先获得SPI总线、CS使能;使用完后再分别释放,从而使其它获得控制权。 rt_err_t rt_spi_take_bus(struct rt_spi_device *device); rt_err_t rt_spi_take(struct rt_spi_device *device); rt_err_t rt_spi_release(struct rt_spi_device *device); rt_err_t rt_spi_release_bus(struct rt_spi_device *device); void rt_spi_message_append (struct rt_spi_message * list, struct rt_spi_message *message);//单链表发送一条消息 二 主设备的操作: 2.1 先挂载已经注册好的SPI设备, rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device, const char

网络IO

穿精又带淫゛_ 提交于 2019-12-03 11:31:26
1、IO介绍 对于一个network IO (这里我们以read举例),它会涉及到两个系统对象,一个是调用这个IO的process (or thread),另一个就是系统内核(kernel)。当一个read操作发生时,该操作会经历两个阶段: #1)等待数据准备 (Waiting for the data to be ready) #2)将数据从内核拷贝到进程中(Copying the data from the kernel to the process) 服务端: from socket import * s = socket() s.bind(('127.0.0.1',8080)) s.listen(5) while True: conn, addr = s.accept() print(addr) while True: try: data = conn.recv(1024) if not data: break print('from client msg: ',data) except ConnectionResetError: break conn.close() #data = conn.recv这里会有一个明显的阻塞效果 #recv本质是从网卡收消息,但应用程序不能操作硬件,它会给操作系统发请求,找操作系统拿数据,操作系统缓存里有没有数据 #取决于网卡

Setting timeout to recv function

两盒软妹~` 提交于 2019-12-03 08:19:42
问题 I read from socket using recv function. I have problem when no data available for reading. My programm just stops. I found that I can set timeout using select function. But looks that timeout affects select function itself and recv that goes after select still waits uncontinuously. fd_set set; struct timeval timeout; FD_ZERO(&set); /* clear the set */ FD_SET(s, &set); /* add our file descriptor to the set */ timeout.tv_sec = SOCKET_READ_TIMEOUT_SEC; timeout.tv_usec = 0; int rv = select(s,

C socket: recv and send all data

心不动则不痛 提交于 2019-12-03 07:40:23
问题 I would like to obtain a behavior similar to this: Server run Client run Client type a command like "help" or other Server responds appropriately go to 3 The problem is that when my function excCommand("help") run just a little text is received and printed. My text file is this: COMMAND HELP: help - Display help quit - Shutdown client only COMMAND HELP is printed. Another problem is that when i type a command nothing is printed and after 2 command client exit. This is the piece in particular:

How do I abort a socket.recv() from another thread in Python

陌路散爱 提交于 2019-12-03 06:00:56
问题 I have a main thread that waits for connection. It spawns client threads that will echo the response from the client (telnet in this case). But say that I want to close down all sockets and all threads after some time, like after 1 connection. How would I do it? If I do clientSocket.close() from the main thread, it won't stop doing the recv . It will only stop if I first send something through telnet, then it will fail doing further sends and recvs. My code looks like this: # Echo server

Download HTTP thru sockets (C)

随声附和 提交于 2019-12-03 04:10:22
Recently I started taking this guide to get myself started on downloading files from the internet. I read it and came up with the following code to download the HTTP body of a website. The only problem is, it's not working. The code stops when calling the recv() call. It does not crash, it just keeps on running. Is this my fault? Am I using the wrong approch? I intent to use the code to not just download the contents of .html-files, but also to download other files (zip, png, jpg, dmg ...). I hope there's somebody that can help me. This is my code: #include <stdio.h> #include <sys/socket.h> /*

Pthread conditional signal - not working as expected

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on a project and trying to use pthread_cond_wait() and pthread_cond_signal() to synchronize two threads. My code looks something like this: pthread_mutex_t lock_it = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t write_it = PTHREAD_COND_INITIALIZER; int main(int argc, char**argv) { pthread_t t_send_segments, t_recv_acks; pthread_create(&t_send_segments, NULL, send_segments, (void*)NULL); pthread_create(&t_recv_acks, NULL, recv_acks, (void*)NULL); pthread_join(t_recv_acks, (void**)NULL); pthread_mutex_destroy(&lock_it); pthread_cond

C++ hooking winsock

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to hook winsock send and recv in order to read all traffic of a process. I am injectin the following code as a dll inside the target process #include "dll.h" #include <windows.h> #include <winsock2.h> #include <iostream> #include <fstream> #pragma comment(lib, "ws2_32.lib") using namespace std; DllClass::DllClass() { } DllClass::~DllClass () { } BYTE hook[6]; BYTE hook2[6]; BYTE jmp[6] = { 0xe9,0x00, 0x00, 0x00, 0x00 ,0xc3 }; ofstream myfile; ofstream myfile2; DWORD HookFunction(LPCSTR lpModule, LPCSTR lpFuncName, LPVOID

docker Mule-server curl: (56) Recv failure: Connection reset by peer

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This might just be my rookie knowledge of Docker, but I can't get the networking to work. I'm trying to run a Mule-server via the pr3d4t0r/mule repository. I can run it, hot-swap applications but I can reach it. I can run a local server without Docker, and it works flawlessly. But not when I try it with Docker. When I try to do a simple curl command I get "curl: (56) Recv failure: Connection reset by peer" curl http://localhost:8090/Sven I have tried exposing the ports via -P and separately via -p 8090:8090 but no luck. When the docker is

python网络编程 - tcp

北战南征 提交于 2019-12-03 01:57:15
网络编程 低级别的网络服务 高级别的网络服务 socket又称“套接字”,应用程序通过“套接字”向网络 发出请求 或者 应答网络请求 ,使 主机间 或者 一台计算机上的进程间 可以通讯。 socket()函数 使用socket()函数来创建套接字,如下: socket.socket([family[,type[,protocol]]]) family:套接字家族,AF_UNIX或者AF_INET type:套接字类型,面向连接的还是面向非连接的,SOCK_STREAM或者SOCK_DGRAM protocol:一般不填默认为0 python代码实现 服务端 流程 1、socket创建一个套接字 2、bind绑定ip和port 3、listen 使套接字变为可以被动链接(默认创建的套接字是主动去链接别人的) 4、accept 等待客户端的链接(accept和客户端的connect是一对,服务器的accept只响应客户端的connect) 5、send/recv 发送和接收数据(recv和send是一夫多妻,服务器的recv响应客户端的send,也响应客户端socket的close;反之亦然)。有一个好玩的事情,当某一端send空数据的时候,另一端recv并没有响应,而当close的时候,recv却是能响应的,不过数据为空,猜测是send不能发送空数据 代码 import socket