Make Select a singleton
It's going to manipulate process-global signal state, so multiple instances do not make sense.
This commit is contained in:
committed by
Keith Winstein
parent
bb651581a7
commit
768d4ce797
@@ -2,7 +2,7 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXF
|
||||
|
||||
noinst_LIBRARIES = libmoshutil.a
|
||||
|
||||
libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h sigfd.h select.h
|
||||
libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h sigfd.h select.h select.cc
|
||||
|
||||
if !USE_LIBSTDDJB
|
||||
libmoshutil_a_SOURCES += sigfd.cc
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Mosh: the mobile shell
|
||||
Copyright 2012 Keith Winstein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "select.h"
|
||||
|
||||
Select *Select::instance = NULL;
|
||||
@@ -33,6 +33,17 @@ static fd_set dummy_fd_set;
|
||||
/* Convenience wrapper for select(2). */
|
||||
class Select {
|
||||
public:
|
||||
static Select &get_instance( void ) {
|
||||
// NB: not thread-safe
|
||||
if ( !instance ) {
|
||||
instance = new Select;
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
|
||||
private:
|
||||
static Select *instance;
|
||||
|
||||
Select()
|
||||
: max_fd( -1 )
|
||||
|
||||
@@ -47,6 +58,11 @@ public:
|
||||
FD_ZERO( &error_fds );
|
||||
}
|
||||
|
||||
/* not implemented */
|
||||
Select( const Select & );
|
||||
Select &operator=( const Select & );
|
||||
|
||||
public:
|
||||
void add_fd( int fd )
|
||||
{
|
||||
if ( fd > max_fd ) {
|
||||
|
||||
Reference in New Issue
Block a user