⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pchannel.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        }    }  }  return FALSE;}BOOL PChannel::Shutdown(ShutdownValue){  return FALSE;}PChannel * PChannel::GetBaseReadChannel() const{  return (PChannel *)this;}PChannel * PChannel::GetBaseWriteChannel() const{  return (PChannel *)this;}///////////////////////////////////////////////////////////////////////////////// PIndirectChannelPIndirectChannel::PIndirectChannel(){  readChannel = writeChannel = NULL;  writeAutoDelete = readAutoDelete = FALSE;}PObject::Comparison PIndirectChannel::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PIndirectChannel::Class()), PInvalidCast);  const PIndirectChannel & other = (const PIndirectChannel &)obj;  return readChannel == other.readChannel &&         writeChannel == other.writeChannel ? EqualTo : GreaterThan;}PString PIndirectChannel::GetName() const{  ((PIndirectChannel*)this)->channelPointerMutex.StartRead();  PString name;  if (readChannel != NULL && readChannel == writeChannel)    name = readChannel->GetName();  else {    name = "R<";    if (readChannel != NULL)      name += readChannel->GetName();    name += "> T<";    if (writeChannel != NULL)      name += writeChannel->GetName();    name += ">";  }  ((PIndirectChannel*)this)->channelPointerMutex.EndRead();  return name;}BOOL PIndirectChannel::Close(){  BOOL retval = TRUE;  flush();  channelPointerMutex.StartRead();  if (readChannel != NULL)    retval = readChannel->Close();  if (readChannel != writeChannel && writeChannel != NULL)    retval = writeChannel->Close() && retval;  channelPointerMutex.EndRead();  channelPointerMutex.StartWrite();  PChannel * r = readChannel;  PChannel * w = writeChannel;  readChannel = NULL;  writeChannel = NULL;  if (readAutoDelete)    delete r;  if (r != w && writeAutoDelete)    delete w;  channelPointerMutex.EndWrite();  return retval;}BOOL PIndirectChannel::IsOpen() const{  ((PIndirectChannel*)this)->channelPointerMutex.StartRead();  BOOL returnValue;  if (readChannel != NULL && readChannel == writeChannel)    returnValue = readChannel->IsOpen();  else {    returnValue = readChannel != NULL ? readChannel->IsOpen() : FALSE;    if (writeChannel != NULL)      returnValue = writeChannel->IsOpen() || returnValue;  }  ((PIndirectChannel*)this)->channelPointerMutex.EndRead();  return returnValue;}BOOL PIndirectChannel::Read(void * buf, PINDEX len){  flush();  channelPointerMutex.StartRead();  PAssert(readChannel != NULL, "Indirect read though NULL channel");  BOOL returnValue;  if (readChannel == NULL)    returnValue = FALSE;  else {    readChannel->SetReadTimeout(readTimeout);    returnValue = readChannel->Read(buf, len);    lastError = readChannel->GetErrorCode();    osError = readChannel->GetErrorNumber();    lastReadCount = readChannel->GetLastReadCount();  }  channelPointerMutex.EndRead();  return returnValue;}BOOL PIndirectChannel::Write(const void * buf, PINDEX len){  flush();  channelPointerMutex.StartRead();  PAssert(writeChannel != NULL, "Indirect write though NULL channel");  BOOL returnValue;  if (writeChannel == NULL)    returnValue = FALSE;  else {    writeChannel->SetWriteTimeout(writeTimeout);    returnValue = writeChannel->Write(buf, len);    lastError = writeChannel->GetErrorCode();    osError = writeChannel->GetErrorNumber();    lastWriteCount = writeChannel->GetLastWriteCount();  }  channelPointerMutex.EndRead();  return returnValue;}BOOL PIndirectChannel::Shutdown(ShutdownValue value){  channelPointerMutex.StartRead();  BOOL returnValue;  if (readChannel != NULL && readChannel == writeChannel)    returnValue = readChannel->Shutdown(value);  else {    returnValue = readChannel != NULL ? readChannel->Shutdown(value) : FALSE;    if (writeChannel != NULL)      returnValue = writeChannel->Shutdown(value) || returnValue;  }  channelPointerMutex.EndRead();  return returnValue;}BOOL PIndirectChannel::Open(PChannel & channel){  return Open(&channel, FALSE);}BOOL PIndirectChannel::Open(PChannel * channel, BOOL autoDelete){  return Open(channel, channel, autoDelete, autoDelete);}BOOL PIndirectChannel::Open(PChannel * readChan,                            PChannel * writeChan,                            BOOL autoDeleteRead,                            BOOL autoDeleteWrite){  Close();  channelPointerMutex.StartWrite();  readChannel = readChan;  readAutoDelete = autoDeleteRead;  writeChannel = writeChan;  writeAutoDelete = autoDeleteWrite;  channelPointerMutex.EndWrite();  return IsOpen() && OnOpen();}BOOL PIndirectChannel::OnOpen(){  return TRUE;}BOOL PIndirectChannel::SetReadChannel(PChannel * channel, BOOL autoDelete){  if (readChannel != NULL) {    lastError = Miscellaneous;    osError = EBADF;    return FALSE;  }  channelPointerMutex.StartWrite();  readChannel = channel;  readAutoDelete = autoDelete;  channelPointerMutex.EndWrite();  return IsOpen();}BOOL PIndirectChannel::SetWriteChannel(PChannel * channel, BOOL autoDelete){  if (writeChannel != NULL) {    lastError = Miscellaneous;    osError = EBADF;    return FALSE;  }  channelPointerMutex.StartWrite();  writeChannel = channel;  writeAutoDelete = autoDelete;  channelPointerMutex.EndWrite();  return IsOpen();}PChannel * PIndirectChannel::GetBaseReadChannel() const{  ((PIndirectChannel*)this)->channelPointerMutex.StartRead();  PChannel * returnValue = readChannel != NULL ? readChannel->GetBaseReadChannel() : 0;  ((PIndirectChannel*)this)->channelPointerMutex.EndRead();  return returnValue;}PChannel * PIndirectChannel::GetBaseWriteChannel() const{  ((PIndirectChannel*)this)->channelPointerMutex.StartRead();  PChannel * returnValue = writeChannel != NULL ? writeChannel->GetBaseWriteChannel() : 0;  ((PIndirectChannel*)this)->channelPointerMutex.EndRead();  return returnValue;}///////////////////////////////////////////////////////////////////////////////// PFilePFile::~PFile(){  Close();}PObject::Comparison PFile::Compare(const PObject & obj) const{  PAssert(obj.IsDescendant(PFile::Class()), PInvalidCast);  return path.Compare(((const PFile &)obj).path);}BOOL PFile::Rename(const PString & newname, BOOL force){  Close();  if (!ConvertOSError(Rename(path, newname, force) ? 0 : -1))    return FALSE;  path = path.GetDirectory() + newname;  return TRUE;}BOOL PFile::Close(){  if (os_handle < 0) {    osError = EBADF;    lastError = NotOpen;    return FALSE;  }  flush();#ifdef WOT_NO_FILESYSTEM  BOOL ok = TRUE;#else  BOOL ok = ConvertOSError(_close(os_handle));#endif  os_handle = -1;  if (removeOnClose)    Remove();  return ok;}BOOL PFile::Read(void * buffer, PINDEX amount){  flush();#ifdef WOT_NO_FILESYSTEM  lastReadCount = 0;#else  lastReadCount = _read(GetHandle(), buffer, amount);#endif  return ConvertOSError(lastReadCount) && lastReadCount > 0;}BOOL PFile::Write(const void * buffer, PINDEX amount){  flush();#ifdef WOT_NO_FILESYSTEM  lastWriteCount = amount;#else  lastWriteCount = _write(GetHandle(), buffer, amount);#endif  return ConvertOSError(lastWriteCount) && lastWriteCount >= amount;}BOOL PFile::Open(const PFilePath & name, OpenMode  mode, int opts){  Close();  SetFilePath(name);  return Open(mode, opts);}off_t PFile::GetLength() const{#ifdef WOT_NO_FILESYSTEM  return 0;#else  off_t pos = _lseek(GetHandle(), 0, SEEK_CUR);  off_t len = _lseek(GetHandle(), 0, SEEK_END);  PAssertOS(_lseek(GetHandle(), pos, SEEK_SET) == pos);  return len;#endif}BOOL PFile::IsEndOfFile() const{  ((PFile *)this)->flush();  return GetPosition() >= GetLength();}BOOL PFile::SetPosition(off_t pos, FilePositionOrigin origin){#ifdef WOT_NO_FILESYSTEM  return TRUE;#else  return _lseek(GetHandle(), pos, origin) == pos;#endif}BOOL PFile::Copy(const PFilePath & oldname, const PFilePath & newname, BOOL force){  PFile oldfile(oldname, ReadOnly);  if (!oldfile.IsOpen())    return FALSE;  PFile newfile(newname,                   WriteOnly, Create|Truncate|(force ? MustExist : Exclusive));  if (!newfile.IsOpen())    return FALSE;  PCharArray buffer(10000);  off_t amount = oldfile.GetLength();  while (amount > 10000) {    if (!oldfile.Read(buffer.GetPointer(), 10000))      return FALSE;    if (!newfile.Write((const char *)buffer, 10000))      return FALSE;    amount -= 10000;  }  if (!oldfile.Read(buffer.GetPointer(), (int)amount))    return FALSE;  if (!newfile.Write((const char *)buffer, (int)amount))    return FALSE;  return newfile.Close();}// End Of File ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -