■ TCP 代码结构
参考:
https://blog.csdn.net/qq_33951180/article/details/68066634
■ socket-client
• 创建socket
socket-client.c -> pa_socket_client_new_unix() -> socket(PF_LOCAL, SOCK_STREAM, 0)
• connect
socket-client.c -> do_connect() -> connect(c->fd, sa, len)
• read/write
socket-client.c ->do_call() -> io = pa_iochannel_new(c->mainloop, c->fd, c->fd)
iochannel.c -> pa_iochannel_new() -> m->source_io(m, ifd, PA_MAINLOOP_API_IO_EVENT_BOTH, callback, io) -> io->callback(io, io->userdata)
pstream.c -> pa_pstream_new() -> pa_iochannel_set_callback(io, io_callback, p) -> io_callback() -> do_something() -> do_write()-> pa_iochannel_write() -> write()
-> do_read()-> pa_iochannel_read() -> read()
■ socket-server
• 创建socket
socket-server.c ->pa_socket_server_new_unix() -> socket()
• 绑定socket
socket-server.c ->pa_socket_server_new_unix() -> bind()
• listen socket
socket-server.c ->pa_socket_server_new_unix() -> listen()
• accept socket
socket-server.c ->callback() -> accept()
• read/write
socket-server.c ->callback() ->pa_iochannel_new(s->mainloop, nfd, nfd)
module-protocol-stub.c -> protocol_new ()
#define protocol_new pa_protocol_native_new
protocol-native.c-> pa_socket_server_set_callback(p->server, on_connection, p) -> pa_pstream_new(p->core->mainloop, io)-> io_callback() -> do_something() -> do_write()-> pa_iochannel_write() -> write()
-> do_read()-> pa_iochannel_read() -> read()