本文整理汇总了C++中Pipe::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Pipe::close方法的具体用法?C++ Pipe::close怎么用?C++ Pipe::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pipe
的用法示例。
在下文中一共展示了Pipe::close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testWriteRead
void testWriteRead ()
{
char outBuff[256];
char inBuff[256];
size_t nbw;
size_t nbr;
strcpy (outBuff, "MyServer is a powerful and easy to configure web server");
int ret = pipe->create ();
CPPUNIT_ASSERT_EQUAL (ret, 0);
ret = pipe->write (outBuff, 256, &nbw);
CPPUNIT_ASSERT_EQUAL (ret, 0);
ret = pipe->read (inBuff, 256, &nbr);
CPPUNIT_ASSERT_EQUAL (ret, 0);
CPPUNIT_ASSERT_EQUAL (nbr, nbw);
CPPUNIT_ASSERT (strcmp (outBuff, inBuff) == 0);
pipe->close ();
}
示例2: testCreateClose
void testCreateClose ()
{
int ret = pipe->create ();
CPPUNIT_ASSERT_EQUAL (pipe->pipeTerminated (), false);
CPPUNIT_ASSERT_EQUAL (ret, 0);
pipe->close ();
CPPUNIT_ASSERT_EQUAL (pipe->pipeTerminated (), true);
}
示例3: testInverted
void testInverted ()
{
Pipe pipeInv;
int ret = pipe->create ();
CPPUNIT_ASSERT_EQUAL (ret, 0);
pipe->inverted (pipeInv);
CPPUNIT_ASSERT (pipeInv.getReadHandle () != pipe->getReadHandle ());
CPPUNIT_ASSERT (pipeInv.getWriteHandle () != pipe->getWriteHandle ());
pipe->close ();
}
示例4: testWaitForData
void testWaitForData ()
{
char outBuff[256];
size_t nbw;
strcpy (outBuff, "MyServer is a powerful and easy to configure web server");
int ret = pipe->create ();
CPPUNIT_ASSERT_EQUAL (pipe->waitForData (0, 100), 0);
ret = pipe->write (outBuff, 256, &nbw);
CPPUNIT_ASSERT_EQUAL (pipe->waitForData (0, 100), 1);
pipe->close ();
}
示例5: main
int main()
{
srand(time_t(NULL));
Pipe p;
bool isConnect = p.connect();
string ans;
while (!isConnect)
{
cout << "cant connect to graphics" << endl;
cout << "Do you try to connect again or exit? (0-try again, 1-exit)" << endl;
cin >> ans;
if (ans == "0")
{
cout << "trying connect again.." << endl;
Sleep(5000);
isConnect = p.connect();
}
else
{
p.close();
return 0;
}
}
char msgToGraphics[1024];
const string START_MASSAGE = "rnbkqbnrpppppppp################################PPPPPPPPRNBKQBNR0";
// msgToGraphics should contain the board string accord the protocol
// YOUR CODE
strcpy_s(msgToGraphics, START_MASSAGE.c_str()); // just example...
Board board(START_MASSAGE);
p.sendMessageToGraphics(msgToGraphics); // send the board string
// get message from graphics
string msgFromGraphics = p.getMessageFromGraphics();
while (msgFromGraphics != "quit")
{
// should handle the string the sent from graphics
// according the protocol. Ex: e2e4 (move e2 to e4)
for(char i = Location::MIN_ROW; i <= Location::MAX_ROW; i++)
{
for(char j = Location::MIN_COL; j <= Location::MAX_COL; j++)
{
if(board[Location(j, i)] != nullptr)
{
cout << board[Location(j, i)]->get_type();
if((board[Location(j, i)]->get_color() == WHITE))
cout << "W ";
else
cout << "B ";
}
else
{
cout << "## ";
}
}
cout << std::endl;
}
//WIP: print recived index and index on board
//cout << msgFromGraphics[0] << msgFromGraphics[1] << Location(msgFromGraphics[0], msgFromGraphics[1]).get_row() << Location(msgFromGraphics[0], msgFromGraphics[1]).get_col() << std::endl;
MoveResult result = board.move(Location(msgFromGraphics[0], msgFromGraphics[1]), Location(msgFromGraphics[2], msgFromGraphics[3]));
strcpy_s(msgToGraphics, std::to_string(result).c_str()); // msgToGraphics should contain the result of the operation
// return result to graphics
p.sendMessageToGraphics(msgToGraphics);
// get message from graphics
msgFromGraphics = p.getMessageFromGraphics();
}
p.close();
}
示例6: Start
/**
start process and return the handle of it
argv[0] = exe
*/
static inline bool Start(Handle* hdl, const std::string& exe, const std::vector<std::string>& arg, bool closeStdio = true)
{
#ifdef _WIN32
cybozu::disable_warning_unused_variable(closeStdio);
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
std::string cmdLine = "\"" + exe + '"';
for (size_t i = 0, n = arg.size(); i < n; i++) {
cmdLine += " \"" + escape(arg[i]) + '"';
}
cmdLine += '\0';
if (!CreateProcess(exe.c_str(), &cmdLine[0], NULL, NULL, FALSE
/* Advanced Windows p.123 */
, CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP | CREATE_DEFAULT_ERROR_MODE, NULL, 0, &si, &pi)) {
return false;
}
if (pi.hThread) CloseHandle(pi.hThread);
// if (pi.hProcess) CloseHandle(pi.hProcess);
*hdl = pi.hProcess;
return true;
#else
Pipe pipe;
if (!pipe.init()) {
return false;
}
pid_t pid = fork();
if (pid < 0) {
return false;
} else if (pid == 0) {
pipe.close(Pipe::Read);
std::vector<char*> argv;
argv.push_back(const_cast<char*>(exe.c_str()));
for (size_t i = 0, n = arg.size(); i < n; i++) {
argv.push_back(const_cast<char*>(arg[i].c_str()));
}
argv.push_back(0);
if (closeStdio) {
if (!toDevNull(0, O_RDONLY)) goto ERR_EXIT;
if (!toDevNull(1, O_RDWR)) goto ERR_EXIT;
if (!toDevNull(2, O_RDWR)) goto ERR_EXIT;
}
{
const int ret = static_cast<int>(sysconf(_SC_OPEN_MAX));
const int maxFd = ret < 0 ? 1024 : maxFd;
for (int i = 3; i < maxFd; i++) {
close(i);
}
}
execv(exe.c_str(), &argv[0]);
ERR_EXIT:
/*
write pipe if execv fails
*/
pipe.write("x", 1);
pipe.close(Pipe::Write);
::exit(1);
}
pipe.close(Pipe::Write);
char buf[1];
/*
if execv succeeds then Pipe::Read is closed and returns error
otherwise gets 'x' from child
*/
if (pipe.read(buf, 1) == 1) {
waitpid(pid, 0, WNOHANG);
return false;
}
*hdl = pid;
return true;
#endif
}
示例7:
BaseDaemon::~BaseDaemon()
{
writeSignalIDtoSignalPipe(SignalListener::StopThread);
signal_listener_thread.join();
signal_pipe.close();
}