試験ノート - 実装ドリル 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
comment_only.c
1// =================================
2// hedear files
3// =================================
4// tip : ip, select
5
6// =================================
7// global variable
8// =================================
9// fd: listen, max, next
10// ids, msgs: 65536 (2^16)
11// fds: read, write, active
12// buf: read[4097], write[200042];
13
14// =================================
15// error
16// =================================
17// static void fatal(void)
18// {
19// // write & exit
20// }
21
22// =================================
23// accept_client() & helper
24// =================================
25
26// static void send_all(int except)
27// {
28// // get size from buff
29//
30// // send fds except new fd or the sender
31// }
32
33// static void accept_client(void)
34// {
35// // get new fd with accept(g_listen_fd, ...) / fatal()
36//
37// // update global vars / write id to buf / then send_all
38//
39// }
40
41// =================================
42// receive_from() & helper
43// =================================
44
45//static void disconnect_client(int fd)
46//{
47// // sprintf : add broadcast left message to buf_write
48// // FD_CLR : extract fd from active fdset
49// // close
50// // send_all
51// // free & set NULL
52//}
53
54// static int extract_message(char **buf, char **msg)
55// {
56// // init *msg
57// // *buf NULL check -> fatal
58// //
59// // string loop :
60// // find char '\n'
61// // new buffer <- after '\n' string
62// // msg <- buffer
63// // buffer <- new buffer
64//
65// }
66
67// static char *str_join(char *buf, char *add)
68// {
69// // len <- buf + add
70// // res allocate & be string
71// // concat buf
72// // free buf
73// // res concat add
74// }
75
76// static void receive_from(int fd)
77// {
78// // call recv()
79//
80// // failure -> hangle disconnect
81//
82// // success -> '\0' / add it to the back
83//
84// // loop : extract until '\n' and send all
85//
86// }
87
88// =================================
89// main()
90// =================================
91
92// int main(int ac, char **av) {
93// // 引数チェック
94//
95// // リスニングソケット作成。失敗でfatal()
96//
97// // struct sockaddr_in を構築
98//
99// // bind, listen を実行。いずれも失敗でfatal()
100//
101// // グローバル状態を初期化
102//
103// // 永久ループ
104//
105// }