/* This file is part of cardwords
   (c) 1999 Tobias Peters
   
   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 2 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, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

//cardwords_serversocket.cc

#include "cardwords_serversocket.hh"
#include "cardwords_participant.hh"
#include "cardwords_server.hh"

void  CardWords_ServerSocket::being_selected(int fd, int mode)
{
  assert (mode == READ_MODE);
  assert (fd == this->fd);
  int newfd = accept (fd, NULL, NULL);
  if (newfd < 0) {
    switch (errno) {
    case EWOULDBLOCK:
      return;
    case EBADF: case ENOTSOCK: case EOPNOTSUPP: case EFAULT: default:
      throw CardWords_XInternal_Error(gettext("Server socket: "\
                                            "accept() failed"));
    }
  }
  (void) // cast to void to avoid warning about unused calculated value.
  new CardWords_Participant(newfd, selector, server_global.engin);
  // the constructor takes care to register a pointer the new object.
}
