Add conn conn_pop_packet.

This commit is contained in:
Colin 2025-09-22 05:33:48 +00:00
parent b9bef6a9af
commit 9ac39e6a12
3 changed files with 48 additions and 16 deletions

51
.vscode/launch.json vendored
View File

@ -5,29 +5,54 @@
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"name": "mini-gdbstub",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/mini-gdbstub/build/emu",
"args": ["./mini-gdbstub/build/emu_test.bin"],
"args": [
"./mini-gdbstub/build/emu_test.bin"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/mini-gdbstub",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "gdbstub",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/gdbstub/build/stub",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/gdbstub",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}

View File

@ -8,5 +8,11 @@ int main(int argc, char *argv[]) {
conn_t conn;
if (!conn_init(&conn, "127.0.0.1", 1234)) std::cout << "conn_init error" << std::endl;
while (1) {
conn_recv_packet(&conn);
packet_t *pkt = conn_pop_packet(&conn);
printf("packet = %s\n", pkt->data);
}
return 0;
}

View File

@ -3,16 +3,17 @@
#include <pthread.h>
#include <stdbool.h>
#include "packet.h"
#define MAX_SEND_PACKET_SIZE (0x1000)
#define MAX_DATA_PAYLOAD (MAX_SEND_PACKET_SIZE - (2 + CSUM_SIZE + 2))
typedef struct {
int listen_fd;
int socket_fd;
int listen_fd;
int socket_fd;
pktbuf_t pktbuf;
pktbuf_t pktbuf;
} conn_t;
bool conn_init(conn_t *conn, char *addr_str, int port);