cmn-clib(CommonLibraryForC)
C言語共通ライブラリ
 全て データ構造 ファイル 関数 変数 型定義 列挙型 列挙値 マクロ定義
CmnNet.h
[詳解]
1 
10 #ifndef CMNCLIB_CMN_NET_H_
11 #define CMNCLIB_CMN_NET_H_
12 
13 #include "cmnclib/Common.h"
14 #include "cmnclib/CmnData.h"
15 #include "cmnclib/CmnThread.h"
16 
17 #if IS_PRATFORM_WINDOWS()
18  #include <winsock2.h>
19 #else
20  #include <sys/types.h>
21  #include <sys/socket.h>
22  #include <netinet/in.h>
23 #endif
24 
26 #define CNS_OPT_GRACEFUL_CLOSE 0x01
27 
29 typedef enum {
42 
44 typedef struct tag_CmnNetSocket {
45 #if IS_PRATFORM_WINDOWS()
46  SOCKET socketId;
47 #else
48  int socketId;
49 #endif
50 } CmnNetSocket;
51 
53 typedef struct tag_CmnNetSocketServer {
58  volatile int _isRunnable;
60 
61 typedef struct tag_CmnNetHttpResponse {
62 /* TODO CmnDataMap(JavaのHashMapみたいなの)が実装されたら有効にすること
63  CmnDataMap *header;
64  */
65  CmnDataBuffer *body;
67 
68 D_EXTERN CmnNetSocketStatus CmnNetSocket_StartServer(unsigned short port, void (*serverMainProc)(CmnNetSocket*), CmnNetSocketServer *server);
70 D_EXTERN CmnNetSocketStatus CmnNetSocket_NoSessionRequest(const char *host, unsigned short port, CmnDataBuffer *request, CmnDataBuffer *response, const char *responseEndMark, const int responseEndMarkLen, int opt);
71 D_EXTERN CmnNetSocketStatus CmnNetSocket_ReceiveAll(CmnNetSocket *socket, CmnDataBuffer *buf, const char *endMark, const int endMarkLen);
72 D_EXTERN CmnNetSocketStatus CmnNetSocket_SendAll(CmnNetSocket *socket, const void *data, int len);
73 D_EXTERN CmnNetSocketStatus CmnNetSocket_ToSocketAddress(const char *host, unsigned short port, struct sockaddr_in *addr);
74 
75 D_EXTERN CmnNetHttpResponse* CmnNetHttp_GetRequest(const char *ip, unsigned short port, const char *path);
76 D_EXTERN CmnNetHttpResponse* CmnNetHttp_PostRequest(const char *ip, unsigned short port, const char *path, CmnDataBuffer *requestBody);
77 
78 #endif /* CMNCLIB_CMN_NET_H_ */
Definition: CmnNet.h:34
スレッドライブラリ ヘッダファイル
Definition: CmnData.h:44
Definition: CmnNet.h:32
Definition: CmnNet.h:40
Definition: CmnNet.h:61
CmnNetSocketStatus errorStatus
Definition: CmnNet.h:57
Definition: CmnNet.h:53
Definition: CmnNet.h:37
D_EXTERN CmnNetSocketStatus CmnNetSocket_ReceiveAll(CmnNetSocket *socket, CmnDataBuffer *buf, const char *endMark, const int endMarkLen)
ソケットからすべてのデータを読み込む
Definition: CmnNetSocket.c:377
void(* serverMainProc)(CmnNetSocket *)
Definition: CmnNet.h:56
構造化データ操作 共通関数 I/Fヘッダファイル
D_EXTERN CmnNetHttpResponse * CmnNetHttp_GetRequest(const char *ip, unsigned short port, const char *path)
HTTPのGETリクエストを送信する
Definition: CmnNetHttp.c:17
D_EXTERN CmnNetSocketStatus CmnNetSocket_NoSessionRequest(const char *host, unsigned short port, CmnDataBuffer *request, CmnDataBuffer *response, const char *responseEndMark, const int responseEndMarkLen, int opt)
セッションレスTCP/IPリクエスト送信
Definition: CmnNetSocket.c:295
struct tag_CmnNetSocketServer CmnNetSocketServer
Definition: CmnNet.h:35
Definition: CmnNet.h:44
Definition: CmnThread.h:33
D_EXTERN CmnNetHttpResponse * CmnNetHttp_PostRequest(const char *ip, unsigned short port, const char *path, CmnDataBuffer *requestBody)
HTTPのPOSTリクエストを送信する
Definition: CmnNetHttp.c:34
共通関数 メインヘッダファイル
D_EXTERN CmnNetSocketStatus CmnNetSocket_EndServer(CmnNetSocketServer *server)
サーバーを終了する
Definition: CmnNetSocket.c:273
Definition: CmnNet.h:33
struct tag_CmnNetSocket CmnNetSocket
D_EXTERN CmnNetSocketStatus CmnNetSocket_StartServer(unsigned short port, void(*serverMainProc)(CmnNetSocket *), CmnNetSocketServer *server)
TCP/IP待ち受けサーバー起動
Definition: CmnNetSocket.c:190
CmnThread * acceptThread
Definition: CmnNet.h:55
Definition: CmnNet.h:30
D_EXTERN CmnNetSocketStatus CmnNetSocket_SendAll(CmnNetSocket *socket, const void *data, int len)
ソケットへすべてのデータを書き込む
Definition: CmnNetSocket.c:419
Definition: CmnNet.h:39
CmnNetSocketStatus
Definition: CmnNet.h:29
int socketId
Definition: CmnNet.h:48
volatile int _isRunnable
Definition: CmnNet.h:58
Definition: CmnNet.h:36
D_EXTERN CmnNetSocketStatus CmnNetSocket_ToSocketAddress(const char *host, unsigned short port, struct sockaddr_in *addr)
IPアドレスやホスト名文字列とポート番号からsockaddr_inを設定する
Definition: CmnNetSocket.c:439
Definition: CmnNet.h:31
Definition: CmnNet.h:38
CmnNetSocket * serverSocket
Definition: CmnNet.h:54