本文整理汇总了C++中LogFile::LogFileSet方法的典型用法代码示例。如果您正苦于以下问题:C++ LogFile::LogFileSet方法的具体用法?C++ LogFile::LogFileSet怎么用?C++ LogFile::LogFileSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogFile
的用法示例。
在下文中一共展示了LogFile::LogFileSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: socket
void
CommunicationObject::Main ()
{
OutputModule *output_module;
output_module = OutputModule::Instance ();
ApplicationSetup* comm_object_application_setup;
comm_object_application_setup = ApplicationSetup::Instance ();
LogFile *logfile;
logfile = LogFile::Instance ();
int client_sock;
int c;
struct sockaddr_in server, client;
int socket_desc;
socket_desc = socket (AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(SERVER_IP);
server.sin_port = htons (SERVER_PORT);
if (FLUSH_OUTPUTMODULETCP == 1)
{
int flag1 = 1;
int result1 = setsockopt(client_sock, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag1, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
}
/*Binding the socket*/
bind (socket_desc, (struct sockaddr *) &server, sizeof (server));
while (go)
{
listen (socket_desc, 1);
c = sizeof (struct sockaddr_in);
if (go == 0)
{
break;
}
client_sock =
accept (socket_desc, (struct sockaddr *) &client, (socklen_t *) & c);
if (FLUSH_OUTPUTMODULETCP == 1)
{
int flag = 1;
int result = setsockopt(client_sock, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
}
if (go == 0)
{
break;
}
if (client_sock >= 0)
{
output_module->OutputModuleStdoutOff();
output_module->OutputModuleSockidOn(client_sock);
output_module->TcpUserArrayInsert (client_sock);
output_module->Output("Welcome: Comunicazione col server stabilita\n");
//Warning: all the following functions like LogFileWriteString will write
//on the log file specified by LogFileSet. If you want to write on another file you have
//to use again the function LogFileSet.
logfile->LogFileSet(comm_object_application_setup->application_setup_general_log_path);
string tmp_address = inet_ntoa(client.sin_addr);
logfile->LogFileWriteString(GetTime() + ": Assigned socket id " + to_string(client_sock) + " to client with ip " + tmp_address + "\n\n");
worker_thread = new thread (&CommunicationObject::Worker, this,
(void *) &client_sock);
worker_thread->detach();
}
} // while go
}
示例2: tmp
void
CommunicationObject::Worker (void *socket_desc)
{
OutputModule *output_module;
output_module = OutputModule::Instance ();
ApplicationSetup* comm_object_application_setup;
comm_object_application_setup = ApplicationSetup::Instance ();
LogFile *logfile;
logfile = LogFile::Instance ();
int j;
int sock = *(int *) socket_desc;
int read_size;
char buffer[STANDARDBUFFERLIMIT];
const char *my_punt;
bzero (buffer, STANDARDBUFFERLIMIT);
while (go)
{
bzero (buffer, STANDARDBUFFERLIMIT);
if ((read_size = recv (sock, buffer, STANDARDBUFFERLIMIT, MSG_NOSIGNAL)) <= 0)
{
//Warning: all the following functions like LogFileWriteString will write
//on the log file specified by LogFileSet. If you want to write on another file you have
//to use again the function LogFileSet.
logfile->LogFileSet(comm_object_application_setup->application_setup_general_log_path);
logfile->LogFileWriteString(GetTime() + ": User with socket id " + to_string(sock) + " disconnected\n\n");
output_module->TcpUserArrayDelete (sock);
return;
}
string tmp(buffer);
auto command_list = explode(tmp, '\n');
int i = 0;
for ( i = 0; i < command_list.size() ; i ++)
{
unique_lock<mutex> ReservedKeyBoardInputAreaHandle(ReservedKeyBoardInputArea);
if (num_mex == MAXCOMMAND)
BlockedProducerInput.wait(ReservedKeyBoardInputAreaHandle);
coda = (coda + 1) % MAXCOMMAND;
//strncpy (command[coda].command_sent_by_user, buffer, STANDARDBUFFERLIMIT - 1);
strncpy (command[coda].command_sent_by_user, command_list[i].c_str(), STANDARDBUFFERLIMIT - 1);
command[coda].user_sockid = sock;
num_mex++;
BlockedConsumerInput.notify_one();
}
} // while go
BlockedConsumerInput.notify_one();
}