📄 staflocalipcconnprovider.cpp
字号:
connected = ConnectToPipe(pipeData, connImpl.readHandle, connImpl.writeHandle, errorBuffer); // If the problem still exists then throw the error if (!connected) { STAFString connectError("Other side closed connection " "(process ended)"); if (errorBuffer) *errorBuffer = connectError.adoptImpl(); return kSTAFBaseOSError; } } } *connection = new STAFLocalConnectionImpl(connImpl); return kSTAFOk; } CATCH_STANDARD("STAFConnectionProviderConnect"); return kSTAFUnknownError;}STAFRC_t STAFConnectionProviderGetMyNetworkIDs( STAFConnectionProvider_t baseProvider, STAFStringConst_t *logicalID, STAFStringConst_t *physicalID, STAFString_t *errorBuffer){ if (baseProvider == 0) return kSTAFInvalidObject; if (logicalID == 0) return kSTAFInvalidParm; if (physicalID == 0) return kSTAFInvalidParm; try { STAFLocalConnectionProviderImpl *provider = static_cast<STAFLocalConnectionProviderImpl *>(baseProvider); *logicalID = (STAFStringConst_t)provider->logicalNetworkID.getImpl(); *physicalID = (STAFStringConst_t)provider->physicalNetworkID.getImpl(); return kSTAFOk; } CATCH_STANDARD("STAFConnectionProviderGetMyNetworkIDs"); return kSTAFUnknownError;}STAFRC_t STAFConnectionProviderGetOptions( STAFConnectionProvider_t baseProvider, STAFObject_t *options, STAFString_t *errorBuffer){ if (baseProvider == 0) return kSTAFInvalidObject; if (options == 0) return kSTAFInvalidParm; try { STAFLocalConnectionProviderImpl *provider = static_cast<STAFLocalConnectionProviderImpl *>(baseProvider); STAFObjectConstructReference(options, provider->options->getImpl()); return kSTAFOk; } CATCH_STANDARD("STAFConnectionProviderGetOptions"); return kSTAFUnknownError;}STAFRC_t STAFConnectionProviderGetProperty( STAFConnectionProvider_t baseProvider, STAFConnectionProviderProperty_t property, STAFStringConst_t *value, STAFString_t *errorBuffer){ if (baseProvider == 0) return kSTAFInvalidObject; if (value == 0) return kSTAFInvalidParm; try { STAFLocalConnectionProviderImpl *provider = static_cast<STAFLocalConnectionProviderImpl *>(baseProvider); if (property == kSTAFConnectionProviderPortProperty) *value = (STAFStringConst_t)provider->portProperty.getImpl(); else if (property == kSTAFConnectionProviderIsSecureProperty) *value = (STAFStringConst_t)provider->isSecureProperty.getImpl(); else return kSTAFInvalidValue; return kSTAFOk; } CATCH_STANDARD("STAFConnectionProviderGetProperty"); return kSTAFUnknownError;}STAFRC_t STAFConnectionRead(STAFConnection_t baseConnection, void *buffer, unsigned int readLength, STAFString_t *errorBuffer){ if (baseConnection == 0) return kSTAFInvalidObject; if ((buffer == 0) && (readLength != 0)) return kSTAFInvalidParm; try { STAFLocalConnectionImpl *connection = static_cast<STAFLocalConnectionImpl *>(baseConnection); BOOL rc = TRUE; DWORD actual = 0; HANDLE connHandle; if (connection->ipcMethod == kNamedPipes) connHandle = connection->pipeHandle; else connHandle = connection->readHandle; for(DWORD current = 0; current < readLength; current += actual) { rc = ReadFile(connHandle, (LPVOID)((char *)buffer + current), (DWORD)(readLength - current), &actual, 0); if (rc == FALSE) { STAFString error = STAFString("ReadFile OSRC=") + GetLastError(); if (errorBuffer) *errorBuffer = error.adoptImpl(); return kSTAFBaseOSError; } if ((actual == 0) && (readLength != 0)) { STAFString error("No data available on pipe"); if (errorBuffer) *errorBuffer = error.adoptImpl(); return kSTAFBaseOSError; } } return kSTAFOk; } CATCH_STANDARD("STAFConnectionRead"); return kSTAFUnknownError;}STAFRC_t STAFConnectionReadUInt(STAFConnection_t connection, unsigned int *uint, STAFString_t *errorBuffer){ if (connection == 0) return kSTAFInvalidObject; if (uint == 0) return kSTAFInvalidParm; STAFRC_t rc = STAFConnectionRead(connection, uint, sizeof(unsigned int), errorBuffer); if (rc == kSTAFOk) *uint = STAFUtilConvertLEUIntToNative(*uint); return rc;}STAFRC_t STAFConnectionReadSTAFString(STAFConnection_t connection, STAFString_t *stafString, STAFString_t *errorBuffer){ if (connection == 0) return kSTAFInvalidObject; if (stafString == 0) return kSTAFInvalidParm; try { // First, get the size of the string unsigned int size = 0; STAFRC_t rc = STAFConnectionReadUInt(connection, &size, errorBuffer); if (rc != kSTAFOk) return rc; // Next read in the actual UTF-8 data char *inputData = new char[size]; rc = STAFConnectionRead(connection, (void *)inputData, size, errorBuffer); if (rc != kSTAFOk) { delete [] inputData; return rc; } // Now, create the actual STAFString unsigned int osRC = 0; rc = STAFStringConstruct(stafString, inputData, size, &osRC); if ((rc == kSTAFBaseOSError) && (errorBuffer != 0)) *errorBuffer = STAFString(osRC).adoptImpl(); delete [] inputData; return rc; } CATCH_STANDARD("STAFConnectionReadSTAFString"); return kSTAFUnknownError;}STAFRC_t STAFConnectionWrite(STAFConnection_t baseConnection, void *buffer, unsigned int writeLength, STAFString_t *errorBuffer){ if (baseConnection == 0) return kSTAFInvalidObject; if ((buffer == 0) && (writeLength != 0)) return kSTAFInvalidParm; try { STAFLocalConnectionImpl *connection = static_cast<STAFLocalConnectionImpl *>(baseConnection); BOOL rc = TRUE; DWORD actual = 0; HANDLE connHandle; if (connection->ipcMethod == kNamedPipes) connHandle = connection->pipeHandle; else connHandle = connection->writeHandle; for(DWORD current = 0; current < writeLength; current += actual) { rc = WriteFile(connHandle, (LPVOID)((char *)buffer + current), (DWORD)(writeLength - current), &actual, 0); if (rc == FALSE) { STAFString error = STAFString("WriteFile OSRC=") + GetLastError(); if (errorBuffer) *errorBuffer = error.adoptImpl(); return kSTAFBaseOSError; } if ((actual == 0) && (writeLength != 0)) { STAFString error("No data written to pipe"); if (errorBuffer) *errorBuffer = error.adoptImpl(); return kSTAFBaseOSError; } } return kSTAFOk; } CATCH_STANDARD("STAFConnectionWrite"); return kSTAFUnknownError;}STAFRC_t STAFConnectionWriteUInt(STAFConnection_t connection, unsigned int uint, STAFString_t *errorBuffer){ unsigned int leUInt = STAFUtilConvertNativeUIntToLE(uint); return STAFConnectionWrite(connection, &leUInt, sizeof(unsigned int), errorBuffer);}STAFRC_t STAFConnectionWriteSTAFString(STAFConnection_t connection, STAFStringConst_t stafString, STAFString_t *errorBuffer){ if (connection == 0) return kSTAFInvalidObject; if (stafString == 0) return kSTAFInvalidObject; try { unsigned int osRC = 0; unsigned int length = 0; const char *buffer = 0; STAFRC_t rc = STAFStringGetBuffer(stafString, &buffer, &length, &osRC); if ((rc == kSTAFBaseOSError) && (errorBuffer != 0)) { *errorBuffer = STAFString(osRC).adoptImpl(); return rc; } rc = STAFConnectionWriteUInt(connection, length, errorBuffer); if (rc == kSTAFOk) { rc = STAFConnectionWrite(connection, const_cast<char *>(buffer), length, errorBuffer); } return rc; } CATCH_STANDARD("STAFConnectionWriteSTAFString"); return kSTAFUnknownError;}STAFRC_t STAFConnectionGetPeerNetworkIDs(STAFConnection_t connection, STAFStringConst_t *logicalID, STAFStringConst_t *physicalID, STAFString_t *errorBuffer){ if (connection == 0) return kSTAFInvalidObject; if (logicalID == 0) return kSTAFInvalidParm; if (physicalID == 0) return kSTAFInvalidParm; try { static STAFString sLocalString("local"); *logicalID = sLocalString.getImpl(); *physicalID = sLocalString.getImpl(); return kSTAFOk; } CATCH_STANDARD("STAFConnectionGetPeerNetworkIDs"); return kSTAFUnknownError;}STAFRC_t STAFConnectionDestruct(STAFConnection_t *baseConnection, STAFString_t *errorBuffer){ if (baseConnection == 0) return kSTAFInvalidParm; if (*baseConnection == 0) return kSTAFInvalidObject; try { STAFLocalConnectionImpl *connection = static_cast<STAFLocalConnectionImpl *>(*baseConnection); if (connection->ipcMethod == kNamedPipes) { // Flush the pipe to allow the client to read the pipe's contents // before disconnecting. Then disconnect the pipe, and close the // handle to this pipe instance. FlushFileBuffers(connection->pipeHandle); DisconnectNamedPipe(connection->pipeHandle); CloseHandle(connection->pipeHandle); } else { CloseHandle(connection->readHandle); CloseHandle(connection->writeHandle); } delete connection; connection = 0; return kSTAFOk; } CATCH_STANDARD("STAFConnectionDestruct"); return kSTAFUnknownError;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -