TcpServer now compilable at least
This commit is contained in:
		| @ -35,6 +35,7 @@ libqsesi_la_SOURCES =  \ | ||||
| 	nwif.c \ | ||||
| 	nwif-cfg.c \ | ||||
| 	nwio.c  \ | ||||
| 	os.c \ | ||||
| 	pio.c  \ | ||||
| 	rwl.c \ | ||||
| 	sck.c \ | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| # Makefile.in generated by automake 1.15 from Makefile.am. | ||||
| # Makefile.in generated by automake 1.14.1 from Makefile.am. | ||||
| # @configure_input@ | ||||
|  | ||||
| # Copyright (C) 1994-2014 Free Software Foundation, Inc. | ||||
| # Copyright (C) 1994-2013 Free Software Foundation, Inc. | ||||
|  | ||||
| # This Makefile.in is free software; the Free Software Foundation | ||||
| # gives unlimited permission to copy and/or distribute it, | ||||
| @ -16,17 +16,7 @@ | ||||
|  | ||||
|  | ||||
| VPATH = @srcdir@ | ||||
| am__is_gnu_make = { \ | ||||
|   if test -z '$(MAKELEVEL)'; then \ | ||||
|     false; \ | ||||
|   elif test -n '$(MAKE_HOST)'; then \ | ||||
|     true; \ | ||||
|   elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ | ||||
|     true; \ | ||||
|   else \ | ||||
|     false; \ | ||||
|   fi; \ | ||||
| } | ||||
| am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' | ||||
| am__make_running_with_option = \ | ||||
|   case $${target_option-} in \ | ||||
|       ?) ;; \ | ||||
| @ -91,19 +81,20 @@ build_triplet = @build@ | ||||
| host_triplet = @host@ | ||||
| @ENABLE_CXX_TRUE@am__append_1 = libqsesixx.la | ||||
| subdir = lib/si | ||||
| DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ | ||||
| 	$(top_srcdir)/ac/depcomp $(noinst_HEADERS) | ||||
| ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | ||||
| am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ | ||||
| am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ | ||||
| 	$(top_srcdir)/m4/ax_check_sign.m4 \ | ||||
| 	$(top_srcdir)/m4/ax_cxx_namespace.m4 \ | ||||
| 	$(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/ax_numval.m4 \ | ||||
| 	$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \ | ||||
| 	$(top_srcdir)/m4/ltargz.m4 $(top_srcdir)/m4/ltdl.m4 \ | ||||
| 	$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ | ||||
| 	$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ | ||||
| 	$(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \ | ||||
| 	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ | ||||
| 	$(top_srcdir)/m4/lt~obsolete.m4 \ | ||||
| 	$(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac | ||||
| am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | ||||
| 	$(ACLOCAL_M4) | ||||
| DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ | ||||
| 	$(am__DIST_COMMON) | ||||
| mkinstalldirs = $(install_sh) -d | ||||
| CONFIG_HEADER = $(top_builddir)/include/qse/config.h | ||||
| CONFIG_CLEAN_FILES = | ||||
| @ -149,9 +140,10 @@ am_libqsesi_la_OBJECTS = libqsesi_la-aio.lo libqsesi_la-aio-pro.lo \ | ||||
| 	libqsesi_la-log.lo libqsesi_la-mtx.lo libqsesi_la-mux.lo \ | ||||
| 	libqsesi_la-nwad.lo libqsesi_la-nwad-skad.lo \ | ||||
| 	libqsesi_la-nwif.lo libqsesi_la-nwif-cfg.lo \ | ||||
| 	libqsesi_la-nwio.lo libqsesi_la-pio.lo libqsesi_la-rwl.lo \ | ||||
| 	libqsesi_la-sck.lo libqsesi_la-sinfo.lo libqsesi_la-sio.lo \ | ||||
| 	libqsesi_la-task.lo libqsesi_la-thr.lo libqsesi_la-tio.lo | ||||
| 	libqsesi_la-nwio.lo libqsesi_la-os.lo libqsesi_la-pio.lo \ | ||||
| 	libqsesi_la-rwl.lo libqsesi_la-sck.lo libqsesi_la-sinfo.lo \ | ||||
| 	libqsesi_la-sio.lo libqsesi_la-task.lo libqsesi_la-thr.lo \ | ||||
| 	libqsesi_la-tio.lo | ||||
| libqsesi_la_OBJECTS = $(am_libqsesi_la_OBJECTS) | ||||
| AM_V_lt = $(am__v_lt_@AM_V@) | ||||
| am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) | ||||
| @ -252,12 +244,12 @@ am__define_uniq_tagged_files = \ | ||||
|   done | $(am__uniquify_input)` | ||||
| ETAGS = etags | ||||
| CTAGS = ctags | ||||
| am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/depcomp | ||||
| DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | ||||
| ACLOCAL = @ACLOCAL@ | ||||
| AMTAR = @AMTAR@ | ||||
| AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ | ||||
| AR = @AR@ | ||||
| ARGZ_H = @ARGZ_H@ | ||||
| AUTOCONF = @AUTOCONF@ | ||||
| AUTOHEADER = @AUTOHEADER@ | ||||
| AUTOMAKE = @AUTOMAKE@ | ||||
| @ -312,11 +304,9 @@ LTDLDEPS = @LTDLDEPS@ | ||||
| LTDLINCL = @LTDLINCL@ | ||||
| LTDLOPEN = @LTDLOPEN@ | ||||
| LTLIBOBJS = @LTLIBOBJS@ | ||||
| LT_ARGZ_H = @LT_ARGZ_H@ | ||||
| LT_CONFIG_H = @LT_CONFIG_H@ | ||||
| LT_DLLOADERS = @LT_DLLOADERS@ | ||||
| LT_DLPREOPEN = @LT_DLPREOPEN@ | ||||
| LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ | ||||
| MAKEINFO = @MAKEINFO@ | ||||
| MANIFEST_TOOL = @MANIFEST_TOOL@ | ||||
| MKDIR_P = @MKDIR_P@ | ||||
| @ -470,6 +460,7 @@ libqsesi_la_SOURCES = \ | ||||
| 	nwif.c \ | ||||
| 	nwif-cfg.c \ | ||||
| 	nwio.c  \ | ||||
| 	os.c \ | ||||
| 	pio.c  \ | ||||
| 	rwl.c \ | ||||
| 	sck.c \ | ||||
| @ -508,6 +499,7 @@ $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps) | ||||
| 	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/si/Makefile'; \ | ||||
| 	$(am__cd) $(top_srcdir) && \ | ||||
| 	  $(AUTOMAKE) --foreign lib/si/Makefile | ||||
| .PRECIOUS: Makefile | ||||
| Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status | ||||
| 	@case '$?' in \ | ||||
| 	  *config.status*) \ | ||||
| @ -602,6 +594,7 @@ distclean-compile: | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-nwif-cfg.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-nwif.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-nwio.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-os.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-pio.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-rwl.Plo@am__quote@ | ||||
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqsesi_la-sck.Plo@am__quote@ | ||||
| @ -800,6 +793,13 @@ libqsesi_la-nwio.lo: nwio.c | ||||
| @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||||
| @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsesi_la_CFLAGS) $(CFLAGS) -c -o libqsesi_la-nwio.lo `test -f 'nwio.c' || echo '$(srcdir)/'`nwio.c | ||||
|  | ||||
| libqsesi_la-os.lo: os.c | ||||
| @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsesi_la_CFLAGS) $(CFLAGS) -MT libqsesi_la-os.lo -MD -MP -MF $(DEPDIR)/libqsesi_la-os.Tpo -c -o libqsesi_la-os.lo `test -f 'os.c' || echo '$(srcdir)/'`os.c | ||||
| @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libqsesi_la-os.Tpo $(DEPDIR)/libqsesi_la-os.Plo | ||||
| @AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='os.c' object='libqsesi_la-os.lo' libtool=yes @AMDEPBACKSLASH@ | ||||
| @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||||
| @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsesi_la_CFLAGS) $(CFLAGS) -c -o libqsesi_la-os.lo `test -f 'os.c' || echo '$(srcdir)/'`os.c | ||||
|  | ||||
| libqsesi_la-pio.lo: pio.c | ||||
| @am__fastdepCC_TRUE@	$(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqsesi_la_CFLAGS) $(CFLAGS) -MT libqsesi_la-pio.lo -MD -MP -MF $(DEPDIR)/libqsesi_la-pio.Tpo -c -o libqsesi_la-pio.lo `test -f 'pio.c' || echo '$(srcdir)/'`pio.c | ||||
| @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libqsesi_la-pio.Tpo $(DEPDIR)/libqsesi_la-pio.Plo | ||||
| @ -1089,8 +1089,6 @@ uninstall-am: uninstall-libLTLIBRARIES | ||||
| 	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ | ||||
| 	tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES | ||||
|  | ||||
| .PRECIOUS: Makefile | ||||
|  | ||||
|  | ||||
| # Tell versions [3.59,3.63) of GNU make to not export all variables. | ||||
| # Otherwise a system limit (for SysV at least) may be exceeded. | ||||
|  | ||||
| @ -25,6 +25,7 @@ | ||||
|  */ | ||||
|  | ||||
| #include <qse/si/TcpServer.hpp> | ||||
| #include <qse/si/os.h> | ||||
|  | ||||
| QSE_BEGIN_NAMESPACE(QSE) | ||||
|  | ||||
| @ -51,10 +52,10 @@ int TcpServer::Client::run () | ||||
| 	// Client is instantiated in the TcpServer thread. | ||||
| 	// so if it is called in the constructor of Client,  | ||||
| 	// it would just block signals to the TcpProxy thread. | ||||
| 	blockAllSignals (); // don't care about the result. | ||||
| 	this->blockAllSignals (); // don't care about the result. | ||||
|  | ||||
| 	guarantee_tcpsocket_close close_socket (&socket); | ||||
| 	if (server->handle_client (&socket, &address) == -1) return -1; | ||||
| 	guarantee_tcpsocket_close close_socket (&this->socket); | ||||
| 	if (server->handle_client(&this->socket, &this->address) <= -1) return -1; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| @ -69,8 +70,8 @@ int TcpServer::Client::stop () QSE_CPP_NOEXCEPT | ||||
| 	//       as it might not be thread-safe. | ||||
| 	//       but it is still ok because Client::stop()  | ||||
| 	//       is rarely called. | ||||
| 	socket.shutdown (); | ||||
| 	socket.close (); | ||||
| 	this->socket.shutdown (); | ||||
| 	this->socket.close (); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| @ -93,44 +94,30 @@ TcpServer::TcpServer (const SocketAddress& address): | ||||
| { | ||||
| } | ||||
|  | ||||
| TcpServer::~TcpServer () | ||||
| TcpServer::~TcpServer () QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	// QSE_ASSERT (server_serving == false); | ||||
| 	this->delete_all_clients (); | ||||
| } | ||||
|  | ||||
| int TcpServer::start (int* err_code) | ||||
| int TcpServer::start (int* err_code) QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	return this->start(true, err_code); | ||||
| } | ||||
|  | ||||
| int TcpServer::open_tcp_socket (Socket& socket, bool winsock_inheritable, int* err_code) | ||||
| int TcpServer::open_tcp_socket (Socket& socket, bool winsock_inheritable, int* err_code) QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	if (socket.open(QSE_AF_INET6, QSE_SOCK_STREAM, 0) <= -1) | ||||
| 	if (socket.open(this->binding_address.getFamily(), QSE_SOCK_STREAM, 0) <= -1) | ||||
| 	{ | ||||
| 		if (err_code) *err_code = ERR_OPEN; | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
|  | ||||
|  | ||||
| #ifdef _WIN32 | ||||
| 	if (winsock_inheritable) | ||||
| 	{ | ||||
| 		SetHandleInformation ( | ||||
| 			(HANDLE)socket.handle(),  | ||||
| 			HANDLE_FLAG_INHERIT, | ||||
| 			HANDLE_FLAG_INHERIT); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		SetHandleInformation ( | ||||
| 			(HANDLE)socket.handle(),  | ||||
| 			HANDLE_FLAG_INHERIT, 0); | ||||
| 	} | ||||
| #if defined(_WIN32) | ||||
| 	SetHandleInformation ((HANDLE)socket.handle(), HANDLE_FLAG_INHERIT, (winsock_inheritable? HANDLE_FLAG_INHERIT: 0)); | ||||
| #endif | ||||
|  | ||||
| 	socket.setReuseAddr (true); | ||||
| 	//socket.setReuseAddr (true); | ||||
| 	//socket.setReusePort (true); | ||||
|  | ||||
| 	if (socket.bind(this->binding_address) <= -1) | ||||
| @ -145,11 +132,11 @@ int TcpServer::open_tcp_socket (Socket& socket, bool winsock_inheritable, int* e | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	socket.enableTimeout (1000); | ||||
| 	//socket.enableTimeout (1000); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
| int TcpServer::start (bool winsock_inheritable, int* err_code) QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	this->server_serving = true; | ||||
| 	if (err_code != QSE_NULL) *err_code = ERR_NONE; | ||||
| @ -175,6 +162,7 @@ int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
|  | ||||
| 			if (this->max_connections > 0 && this->max_connections <= this->client_list.getSize())  | ||||
| 			{ | ||||
| 				// too many connections. accept the connection and close it. | ||||
| 				Socket s; | ||||
| 				SocketAddress sa; | ||||
| 				if (socket.accept(&s, &sa, Socket::T_CLOEXEC) >= 0) s.close(); | ||||
| @ -191,7 +179,7 @@ int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
| 			} | ||||
| 			if (client == QSE_NULL)  | ||||
| 			{ | ||||
| 				// memory alloc failed | ||||
| 				// memory alloc failed. accept the connection and close it. | ||||
| 				Socket s; | ||||
| 				SocketAddress sa; | ||||
| 				if (socket.accept(&s, &sa, Socket::T_CLOEXEC) >= 0) s.close(); | ||||
| @ -218,8 +206,13 @@ int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
| 				reopen: | ||||
| 					if (this->open_tcp_socket (socket, winsock_inheritable, err_code) <= -1) | ||||
| 					{ | ||||
| 						if (reopen_count >= 200) qse_sleep (100); | ||||
| 						else if (reopen_count >= 100) qse_sleep (10); | ||||
| 						if (reopen_count >= 100)  | ||||
| 						{ | ||||
| 							qse_ntime_t interval; | ||||
| 							if (reopen_count >= 200) qse_inittime (&interval, 0, 100000000); // 100 milliseconds | ||||
| 							else qse_inittime (&interval, 0, 10000000); // 10 milliseconds | ||||
| 							qse_sleep (&interval); | ||||
| 						} | ||||
|  | ||||
| 						if (this->isStopRequested()) break; | ||||
| 						reopen_count++; | ||||
| @ -229,8 +222,8 @@ int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
| 				continue; | ||||
| 			} | ||||
|  | ||||
| 			client->setStackSize (thread_stack_size); | ||||
| 		#ifdef _WIN32 | ||||
| 			client->setStackSize (this->thread_stack_size); | ||||
| 		#if defined(_WIN32) | ||||
| 			if (client->start(Thread::DETACHED) == -1)  | ||||
| 		#else | ||||
| 			if (client->start(0) == -1) | ||||
| @ -265,17 +258,17 @@ int TcpServer::start (bool winsock_inheritable, int* err_code) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int TcpServer::stop () | ||||
| int TcpServer::stop () QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	if (server_serving) setStopRequested (true); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void TcpServer::delete_dead_clients () | ||||
| void TcpServer::delete_dead_clients () QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	ClientList::Node* np, * np2; | ||||
| 	 | ||||
| 	np = client_list.getHeadNode(); | ||||
| 	np = this->client_list.getHeadNode(); | ||||
| 	while (np)  | ||||
| 	{ | ||||
| 		Client* p = np->value; | ||||
| @ -283,12 +276,13 @@ void TcpServer::delete_dead_clients () | ||||
|  | ||||
| 		if (p->getState() != Thread::RUNNING) | ||||
| 		{ | ||||
| #ifndef _WIN32 | ||||
| 		#if !defined(_WIN32) | ||||
| 			p->join (); | ||||
| #endif | ||||
| 		#endif | ||||
|  | ||||
| 			delete p; | ||||
| 			np2 = np; np = np->getNextNode(); | ||||
| 			client_list.remove (np2); | ||||
| 			this->client_list.remove (np2); | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| @ -296,31 +290,31 @@ void TcpServer::delete_dead_clients () | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void TcpServer::delete_all_clients () | ||||
| void TcpServer::delete_all_clients () QSE_CPP_NOEXCEPT | ||||
| { | ||||
| 	ClientList::Node* np, * np2; | ||||
| 	Client* p; | ||||
|  | ||||
| 	for (np = client_list.getHeadNode(); np; np = np->getNextNode())  | ||||
| 	for (np = this->client_list.getHeadNode(); np; np = np->getNextNode())  | ||||
| 	{ | ||||
| 		p = np->value; | ||||
| 		if (p->getState() == Thread::RUNNING) p->stop(); | ||||
| 	} | ||||
|  | ||||
| 	np = client_list.getHeadNode(); | ||||
| 	np = this->client_list.getHeadNode(); | ||||
| 	while (np != QSE_NULL)  | ||||
| 	{ | ||||
| 		p = np->value; | ||||
| 		QSE_ASSERT (p != QSE_NULL); | ||||
|  | ||||
| #ifdef _WIN32 | ||||
| #if defined(_WIN32) | ||||
| 		while (p->state() == Thread::RUNNING) qse_sleep (300); | ||||
| #else	 | ||||
| 		p->join (); | ||||
| #endif | ||||
| 		delete p; | ||||
| 		np2 = np; np = np->getNextNode(); | ||||
| 		client_list.remove (np2); | ||||
| 		this->client_list.remove (np2); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
							
								
								
									
										55
									
								
								qse/lib/si/os.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								qse/lib/si/os.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | ||||
|  | ||||
| /* | ||||
|  * $Id$ | ||||
|  * | ||||
|     Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. | ||||
|  | ||||
|     Redistribution and use in source and binary forms, with or without | ||||
|     modification, are permitted provided that the following conditions | ||||
|     are met: | ||||
|     1. Redistributions of source code must retain the above copyright | ||||
|        notice, this list of conditions and the following disclaimer. | ||||
|     2. Redistributions in binary form must reproduce the above copyright | ||||
|        notice, this list of conditions and the following disclaimer in the | ||||
|        documentation and/or other materials provided with the distribution. | ||||
|  | ||||
|     THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EQSERESS OR | ||||
|     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
|     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
|     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
|     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
|     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
|     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
|     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
|     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
|     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
|  | ||||
|  | ||||
| #include <qse/si/os.h> | ||||
|  | ||||
| #if defined(HAVE_TIME_H) | ||||
| #	include <time.h> | ||||
| #endif | ||||
| #if defined(HAVE_SYS_TIME_H) | ||||
| #	include <sys/time.h> | ||||
| #endif | ||||
|  | ||||
| void qse_sleep (const qse_ntime_t* interval) | ||||
| { | ||||
| #if defined(_WIN32) | ||||
| 	DWORD milli = QSE_SECNSEC_TO_MSEC(interval->sec, interval->nsec); | ||||
| 	Sleep (milli); | ||||
| #elif defined(__OS2__) | ||||
| 	ULONG milli = QSE_SECNSEC_TO_MSEC(interval->sec, interval->nsec); | ||||
| 	DosSleep (milli); | ||||
| #elif defined(HAVE_NANOSLEEP) | ||||
| 	struct timespec ts; | ||||
| 	ts.tv_sec = interval->sec; | ||||
| 	ts.tv_nsec = interval->nsec; | ||||
| 	nanosleep (&ts, &ts); | ||||
| #else | ||||
| 	sleep (interval->sec); | ||||
| #endif | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user