summaryrefslogtreecommitdiff
path: root/third_party/mcpc/tst/commtst.h
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-06-30 19:03:25 +0900
committertanaka takashi <isazaka@gmail.com>2026-06-30 19:03:25 +0900
commit05c8e0a31a0d4192c590e833b24393208e1c751f (patch)
treef7c2c82c9327abde67bf3acf1d0258573b3bc6c2 /third_party/mcpc/tst/commtst.h
parent4bc721c3bf7589b519c5730d093f704ce56e3f09 (diff)
fix: MCPCをvendored fork化しMCP準拠と接続安定性を改善
- Git submoduleを廃止してMCPCを直接管理 - Windowsで254リクエスト付近に発生する切断を修正 - JSON-RPC 2.0エラー応答を標準化 - tool schemaとruntimeの必須・任意引数を一致 - 1000回連続呼び出しの回帰テストを追加
Diffstat (limited to 'third_party/mcpc/tst/commtst.h')
-rw-r--r--third_party/mcpc/tst/commtst.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/third_party/mcpc/tst/commtst.h b/third_party/mcpc/tst/commtst.h
new file mode 100644
index 0000000..49dcc93
--- /dev/null
+++ b/third_party/mcpc/tst/commtst.h
@@ -0,0 +1,147 @@
+#ifndef h_commtst
+#define h_commtst
+
+
+// clang-format off
+#ifdef is_unix
+#define _POSIX_SOURCE
+#include <ctype.h>
+#include <stdio.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <signal.h>
+#include <spawn.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#endif
+
+#ifdef is_win
+
+/* # define _WINSOCKAPI_ */
+#include <fcntl.h>
+#include <stdio.h>
+#include <winsock2.h>
+/* # include <windows.h> */
+#include <io.h>
+#include <ws2tcpip.h>
+#include "commtst.h"
+
+#endif
+// clang-format on
+
+#include <mcpc/_c23_keywords.h>
+#include <mcpc/_c23_uchar.h>
+#include <ext_string.h>
+#include <ext_stdint.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ass0(f) \
+ do { \
+ int ec = (f); \
+ if (0 != ec) { \
+ fprintf(stderr, \
+ "%s:%d,ec:%d syserr:%s\n", \
+ __FILE__, \
+ __LINE__, \
+ ec, \
+ strerror(errno)); \
+ abort(); \
+ } \
+ } while (0)
+
+#define assT(f) \
+ do { \
+ if (!(f)) { \
+ fprintf(stderr, \
+ "abort@%s:%d,syserr:%s\n", \
+ __FILE__, \
+ __LINE__, \
+ strerror(errno)); \
+ abort(); \
+ } \
+ } while (0)
+
+#define assF(f) \
+ do { \
+ if ((f)) { \
+ fprintf(stderr, \
+ "abort@%s:%d,syserr:%s\n", \
+ __FILE__, \
+ __LINE__, \
+ strerror(errno)); \
+ abort(); \
+ } \
+ } while (0)
+
+#define assTcb(f, cb) \
+ do { \
+ if (!(f)) { \
+ { cb }; \
+ fprintf(stderr, "abort@%s:%d\n", __FILE__, __LINE__); \
+ abort(); \
+ } \
+ } while (0)
+
+#define BUFCAP 1024
+#define PORT 8080
+
+typedef int8_t i8_t;
+typedef uint8_t u8_t;
+typedef int16_t i16_t;
+typedef uint16_t u16_t;
+typedef int32_t i32_t;
+typedef uint32_t u32_t;
+typedef int64_t i64_t;
+typedef uint64_t u64_t;
+
+typedef char8_t ch8_t;
+
+typedef size_t sz_t;
+
+#ifdef is_win
+typedef SSIZE_T ssize_t;
+#endif
+
+void read_atmost (void *src, char *rbuf, const size_t nexact, size_t *nread);
+
+void recv_atmost (
+#ifdef is_unix
+ int csock,
+#elif defined(is_win)
+ SOCKET cosck,
+#endif
+ char *rbuf, const size_t nmost, size_t *nread);
+
+int32_t read_u8str (const char8_t * const filename, char8_t * const destbuf);
+
+int32_t read_u8str_sz (const char8_t * const filename, char8_t * const destbuf, size_t *nread);
+
+void zero_trailing_white_char (char8_t * buf, const size_t len);
+
+void zero_trailing_white_char2 (char8_t * buf, size_t *len);
+
+
+#ifdef is_unix
+FILE *unix_fd2strm_r (int fd);
+#endif
+
+#ifdef is_win
+FILE *win_handle2strm (HANDLE h);
+#endif
+
+#ifdef is_win
+int win_handle2fd (HANDLE h);
+#endif
+
+
+#endif