1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| BOOL error_result = TRUE;
Int32 error_test = NULL;
char* mysqldump_db_string = NULL;
char* recv_data = NULL;
LPCWSTR pipe_name = NULL;
char* char_pipe_name = NULL;
HANDLE pipe = NULL;
HANDLE thread = NULL;
pipe_name = L"\\\\.\\pipe\\mysqldump";
char_pipe_name = "\\\\.\\pipe\\mysqldump";
// Contruction of the mysqldump exec string
mysqldump_db_string = (char*)malloc(33+strlen(ConSQL->repertory)+strlen(ConSQL->login)+strlen(ConSQL->password)+strlen(ConSQL->instance)+strlen(ConSQL->database)+strlen(char_pipe_name));
sprintf(mysqldump_db_string, "\"\"%smysqldump.exe\" -u %s -p%s -P %s \"%s\" > \"%s\"\"", ConSQL->repertory, ConSQL->login, ConSQL->password, ConSQL->instance, ConSQL->database, char_pipe_name);
// Create the Named Pipe
printf("Creating the named pipe...\n");
pipe = CreateNamedPipe(
pipe_name, // name of the pipe
PIPE_ACCESS_DUPLEX, Read/Write
PIPE_TYPE_BYTE,// send data as a byte stream
1, // only allow 1 instance of this pipe
0, // no outbound buffer
0, // no inbound buffer
0, // use default wait time
NULL // use default security attributes
);
if(pipe == NULL || pipe == INVALID_HANDLE_VALUE)
{
printf("Failed to create the named pipe: %s\n", char_pipe_name);
return 1;
}
// Execute the mysqldump using a thread
printf("Launching MySQLDump Thread...\n");
thread = CreateThread(NULL, 0, &Thread_MySQLDump, (LPVOID)&mysqldump_db_string, 0, NULL);
if( thread == NULL )
{
printf("Failed to launch the MySQLDump Thread!\n");
return 2;
}
// This call blocks until a client process connects to the pipe
printf("Waiting for a connection...\n");
error_result = ConnectNamedPipe(pipe, NULL);
if (!error_result)
{
printf("Failed to make connection on named pipe\n");
CloseHandle(pipe);
return 3;
}
printf("Connected!\n");
/*
ICI je continue en lisant sur la pipe avec ReadFile
*/ |
Partager