fdconnection.cpp
来自「linux下的异步通信库 支持TCP和UDP异步通信 编译和使用前先读readm」· C++ 代码 · 共 71 行
CPP
71 行
/* * 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 Library 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. */// FdConnection.cpp - Copyright Simon Brenner 2002,2005#include <fcntl.h>#include "FdConnection.hpp"#include "async.h"FdConnection::~FdConnection(){ if (LastSocketObject(fd)) RemoveSocket(fd, this);}bool FdConnection::Connect(){ return true;}void FdConnection::Disconnect(){}bool FdConnection::Write(void *buf, uint len){ return !(write(fd, buf, len)<0);}bool FdConnection::Read(void *buf, uint len, uint *bytesRead){ int ret=read(fd, buf, len); if (bytesRead != NULL) *bytesRead=ret; return !(ret < 0);}bool FdConnection::setNonBlocking(bool non_block){ int oldflags=fcntl(fd, F_GETFL, 0); if (oldflags == -1) return true; if (non_block) oldflags |= O_NONBLOCK; else oldflags &= ~O_NONBLOCK; return fcntl(fd, F_SETFL, oldflags);}void FdConnection::OnRead(){}void FdConnection::OnWrite(){}void FdConnection::OnClose(){}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?