/* * Baltisot * Copyright (C) 1999-2007 Nicolas "Pixel" Noble * * 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 */ /* $Id: SocketClient.cc,v 1.2 2007-10-15 13:47:12 pixel Exp $ */ #include #include #include #include #include #include timeval default_socket_timeout = { 8, 0 }; SocketClient::SocketClient(const String & host, int port, timeval _timeout) : timeout(_timeout) { s.SetNonBlock(); s.Connect(host, 25); if (s.IsConnected()) { SetBurst(); } else { WaitFor(timeout); WaitFor(&s, W4_WRITING); } } SocketClient::~SocketClient() { } String SocketClient::GetStatus() { return status; } void SocketClient::SetStatus(const String & _status) { status = _status; } void SocketClient::subDo() throw (GeneralException) { switch (current) { case 0: if (s.IsConnecting() && (TaskMan::Event() == Task::EVT_HANDLE)) { s.FinalizeConnect(); } if (TaskMan::Event() == Task::EVT_TIMEOUT) { status = "Connection timeout"; Suspend(TASK_DONE); } if (!s.IsConnected()) { status = "Connection failed"; Suspend(TASK_DONE); } RemoveTimeout(); return; default: if (c) delete c; c = 0; if (TaskMan::Event() == Task::EVT_TIMEOUT) { status = "Connection timeout."; Suspend(TASK_DONE); } RemoveTimeout(); return; } } void SocketClient::WaitTimeout() { WaitFor(timeout); }