Ejemplo n.º 1
0
void init_kgio_connect(void)
{
	VALUE mKgio = rb_define_module("Kgio");
	VALUE cSocket = rb_const_get(rb_cObject, rb_intern("Socket"));
	VALUE mSocketMethods = rb_const_get(mKgio, rb_intern("SocketMethods"));
	VALUE cKgio_Socket, cTCPSocket, cUNIXSocket;

	/*
	 * Document-class: Kgio::Socket
	 *
	 * A generic socket class with Kgio::SocketMethods included.
	 * This is returned by all Kgio methods that accept(2) a connected
	 * stream socket.
	 */
	cKgio_Socket = rb_define_class_under(mKgio, "Socket", cSocket);
	rb_include_module(cKgio_Socket, mSocketMethods);
	rb_define_singleton_method(cKgio_Socket, "new", kgio_new, -1);
	rb_define_singleton_method(cKgio_Socket, "connect", kgio_connect, 1);
	rb_define_singleton_method(cKgio_Socket, "start", kgio_start, 1);
#if defined(MSG_FASTOPEN) && defined(KGIO_HAVE_THREAD_CALL_WITHOUT_GVL)
	rb_define_method(cKgio_Socket, "kgio_fastopen", fastopen, 2);
#endif
	/*
	 * Document-class: Kgio::TCPSocket
	 *
	 * Kgio::TCPSocket should be used in place of the plain TCPSocket
	 * when kgio_* methods are needed.
	 */
	cTCPSocket = rb_const_get(rb_cObject, rb_intern("TCPSocket"));
	cTCPSocket = rb_define_class_under(mKgio, "TCPSocket", cTCPSocket);
	rb_include_module(cTCPSocket, mSocketMethods);
	rb_define_singleton_method(cTCPSocket, "new", kgio_tcp_connect, 2);
	rb_define_singleton_method(cTCPSocket, "start", kgio_tcp_start, 2);

	/*
	 * Document-class: Kgio::UNIXSocket
	 *
	 * Kgio::UNIXSocket should be used in place of the plain UNIXSocket
	 * when kgio_* methods are needed.
	 */
	cUNIXSocket = rb_const_get(rb_cObject, rb_intern("UNIXSocket"));
	cUNIXSocket = rb_define_class_under(mKgio, "UNIXSocket", cUNIXSocket);
	rb_include_module(cUNIXSocket, mSocketMethods);
	rb_define_singleton_method(cUNIXSocket, "new", kgio_unix_connect, 1);
	rb_define_singleton_method(cUNIXSocket, "start", kgio_unix_start, 1);
	init_sock_for_fd();
}
Ejemplo n.º 2
0
void init_kgio_accept(void)
{
	VALUE cUNIXServer, cTCPServer;
	VALUE mKgio = rb_define_module("Kgio");

	localhost = rb_const_get(mKgio, rb_intern("LOCALHOST"));
	cKgio_Socket = rb_const_get(mKgio, rb_intern("Socket"));
	cClientSocket = cKgio_Socket;
	mSocketMethods = rb_const_get(mKgio, rb_intern("SocketMethods"));

	rb_define_method(mSocketMethods, "kgio_addr!", addr_bang, 0);

	rb_define_singleton_method(mKgio, "accept_cloexec?", get_cloexec, 0);
	rb_define_singleton_method(mKgio, "accept_cloexec=", set_cloexec, 1);
	rb_define_singleton_method(mKgio, "accept_nonblock?", get_nonblock, 0);
	rb_define_singleton_method(mKgio, "accept_nonblock=", set_nonblock, 1);
	rb_define_singleton_method(mKgio, "accept_class=", set_accepted, 1);
	rb_define_singleton_method(mKgio, "accept_class", get_accepted, 0);

	/*
	 * Document-class: Kgio::UNIXServer
	 *
	 * Kgio::UNIXServer should be used in place of the plain UNIXServer
	 * when kgio_accept and kgio_tryaccept methods are needed.
	 */
	cUNIXServer = rb_const_get(rb_cObject, rb_intern("UNIXServer"));
	cUNIXServer = rb_define_class_under(mKgio, "UNIXServer", cUNIXServer);
	rb_define_method(cUNIXServer, "kgio_tryaccept", unix_tryaccept, -1);
	rb_define_method(cUNIXServer, "kgio_accept", unix_accept, -1);

	/*
	 * Document-class: Kgio::TCPServer
	 *
	 * Kgio::TCPServer should be used in place of the plain TCPServer
	 * when kgio_accept and kgio_tryaccept methods are needed.
	 */
	cTCPServer = rb_const_get(rb_cObject, rb_intern("TCPServer"));
	cTCPServer = rb_define_class_under(mKgio, "TCPServer", cTCPServer);

	rb_define_method(cTCPServer, "kgio_tryaccept", tcp_tryaccept, -1);
	rb_define_method(cTCPServer, "kgio_accept", tcp_accept, -1);
	init_sock_for_fd();
	iv_kgio_addr = rb_intern("@kgio_addr");
}