Commit 2ab6a775 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Implement mailslots.

parent 96409189
......@@ -1217,9 +1217,11 @@ HANDLE WINAPI CreateFileW( LPCWSTR filename, DWORD access, DWORD sharing,
if (!strncmpW(filename, bkslashes_with_dotW, 4))
{
static const WCHAR pipeW[] = {'P','I','P','E','\\',0};
static const WCHAR mailslotW[] = {'M','A','I','L','S','L','O','T','\\',0};
if ((isalphaW(filename[4]) && filename[5] == ':' && filename[6] == '\0') ||
!strncmpiW( filename + 4, pipeW, 5 ))
!strncmpiW( filename + 4, pipeW, 5 ) ||
!strncmpiW( filename + 4, mailslotW, 9 ))
{
dosdev = 0;
}
......
......@@ -1641,9 +1641,31 @@ BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
LPDWORD lpNextSize, LPDWORD lpMessageCount,
LPDWORD lpReadTimeout )
{
FIXME("(%p): stub\n",hMailslot);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
BOOL r;
TRACE("%p %p %p %p %p\n",hMailslot,
lpMaxMessageSize,lpNextSize,lpMessageCount,lpReadTimeout);
SERVER_START_REQ( set_mailslot_info )
{
req->handle = hMailslot;
req->flags = 0;
r = !wine_server_call_err( req );
if( r )
{
if( lpMaxMessageSize )
*lpMaxMessageSize = reply->max_msgsize;
if( lpNextSize )
*lpNextSize = reply->next_msgsize;
if( lpMessageCount )
*lpMessageCount = reply->msg_count;
if( lpReadTimeout )
*lpReadTimeout = reply->read_timeout;
}
}
SERVER_END_REQ;
return r;
}
......@@ -1662,9 +1684,20 @@ BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
*/
BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
{
FIXME("%p %ld: stub\n", hMailslot, dwReadTimeout);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
BOOL r;
TRACE("%p %ld\n", hMailslot, dwReadTimeout);
SERVER_START_REQ( set_mailslot_info )
{
req->handle = hMailslot;
req->flags = MAILSLOT_SET_READ_TIMEOUT;
req->read_timeout = dwReadTimeout;
r = !wine_server_call_err( req );
}
SERVER_END_REQ;
return r;
}
......
......@@ -67,8 +67,6 @@ static int mailslot_test()
ok( GetLastError() == ERROR_PATH_NOT_FOUND,
"error should be ERROR_PATH_NOT_FOUND\n");
todo_wine
{
/* valid open, but with wacky parameters ... then check them */
hSlot = CreateMailslot( szmspath, -1, -1, NULL );
ok( hSlot != INVALID_HANDLE_VALUE , "mailslot with valid name failed\n");
......@@ -77,22 +75,15 @@ static int mailslot_test()
"getmailslotinfo failed\n");
ok( dwMax == ~0UL, "dwMax incorrect\n");
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
}
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
todo_wine
{
ok( dwTimeout == ~0UL, "dwTimeout incorrect\n");
ok( GetMailslotInfo( hSlot, NULL, NULL, NULL, NULL ),
"getmailslotinfo failed\n");
ok( CloseHandle(hSlot), "failed to close mailslot\n");
}
todo_wine
{
/* now open it for real */
hSlot = CreateMailslot( szmspath, 0, 0, NULL );
ok( hSlot != INVALID_HANDLE_VALUE , "valid mailslot failed\n");
}
/* try and read/write to it */
count = 0;
......@@ -106,8 +97,6 @@ static int mailslot_test()
hWriter = CreateFile(szmspath, GENERIC_READ|GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
ok( hWriter == INVALID_HANDLE_VALUE, "bad sharing mode\n");
todo_wine
{
ok( GetLastError() == ERROR_SHARING_VIOLATION,
"error should be ERROR_SHARING_VIOLATION\n");
......@@ -115,7 +104,6 @@ static int mailslot_test()
hWriter = CreateFile(szmspath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
ok( hWriter != INVALID_HANDLE_VALUE, "existing mailslot\n");
}
/*
* opening a client should make no difference to
......@@ -132,11 +120,8 @@ static int mailslot_test()
*/
ok( !ReadFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
"can read client\n");
todo_wine
{
ok( WriteFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
"can't write client\n");
}
ok( !ReadFile( hWriter, buffer, sizeof buffer/2, &count, NULL),
"can read client\n");
......@@ -144,12 +129,9 @@ static int mailslot_test()
* seeing as there's something in the slot,
* we should be able to read it once
*/
todo_wine
{
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
"slot read\n");
ok( count == (sizeof buffer/2), "short read\n" );
}
/* but not again */
ok( !ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
......@@ -174,8 +156,6 @@ static int mailslot_test()
hSlot2 = CreateMailslot( szmspath, 0, 0, NULL );
ok( hSlot2 == INVALID_HANDLE_VALUE , "opened two mailslots\n");
todo_wine
{
/* close the client again */
ok( CloseHandle( hWriter ), "closing the client\n");
......@@ -186,7 +166,6 @@ static int mailslot_test()
hWriter = CreateFile(szmspath, GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
ok( hWriter != INVALID_HANDLE_VALUE, "sharing writer\n");
}
/*
* now try open another as a writer ...
......@@ -196,8 +175,6 @@ static int mailslot_test()
FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
ok( hWriter2 == INVALID_HANDLE_VALUE, "greedy writer succeeded\n");
todo_wine
{
/* now try open another as a writer ... and share with the first */
hWriter2 = CreateFile(szmspath, GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
......@@ -208,7 +185,6 @@ static int mailslot_test()
ok( GetMailslotInfo( hSlot, &dwMax, &dwNext, &dwMsgCount, &dwTimeout ),
"getmailslotinfo failed\n");
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
}
ok( dwMax == 0, "dwMax incorrect\n");
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
ok( dwTimeout == 0, "dwTimeout incorrect\n");
......@@ -217,8 +193,6 @@ static int mailslot_test()
ok( !ReadFile( hSlot, buffer, sizeof buffer, &count, NULL), "slot read\n");
/* write two messages */
todo_wine
{
buffer[0] = 'a';
ok( WriteFile( hWriter, buffer, 1, &count, NULL), "1st write failed\n");
......@@ -226,7 +200,9 @@ static int mailslot_test()
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
todo_wine {
ok( dwNext == 1, "dwNext incorrect\n");
}
ok( dwMsgCount == 1, "dwMsgCount incorrect\n");
buffer[0] = 'b';
......@@ -237,8 +213,10 @@ static int mailslot_test()
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
todo_wine {
ok( dwNext == 1, "dwNext incorrect\n");
ok( dwMsgCount == 2, "dwMsgCount incorrect\n");
}
/* write a 3rd message with zero size */
ok( WriteFile( hWriter2, buffer, 0, &count, NULL), "3rd write failed\n");
......@@ -247,8 +225,10 @@ static int mailslot_test()
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
todo_wine {
ok( dwNext == 1, "dwNext incorrect\n");
ok( dwMsgCount == 3, "dwMsgCount incorrect\n");
}
buffer[0]=buffer[1]=0;
......@@ -265,8 +245,10 @@ static int mailslot_test()
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
todo_wine {
ok( dwNext == 2, "dwNext incorrect\n");
ok( dwMsgCount == 2, "dwMsgCount incorrect\n");
}
/* read the second message */
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
......@@ -278,13 +260,13 @@ static int mailslot_test()
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
}
todo_wine {
ok( dwNext == 0, "dwNext incorrect\n");
todo_wine
{
ok( dwMsgCount == 1, "dwMsgCount incorrect\n");
}
/* read the 3rd (zero length) message */
todo_wine {
ok( ReadFile( hSlot, buffer, sizeof buffer, &count, NULL),
"3rd slot read failed\n");
}
......@@ -294,13 +276,10 @@ static int mailslot_test()
* now there should be no more messages
* check the mailslot info
*/
todo_wine
{
dwNext = dwMsgCount = 0;
ok( GetMailslotInfo( hSlot, NULL, &dwNext, &dwMsgCount, NULL ),
"getmailslotinfo failed\n");
ok( dwNext == MAILSLOT_NO_MESSAGE, "dwNext incorrect\n");
}
ok( dwMsgCount == 0, "dwMsgCount incorrect\n");
/* check that reads fail */
......@@ -308,12 +287,9 @@ static int mailslot_test()
"3rd slot read succeeded\n");
/* finally close the mailslot and its client */
todo_wine
{
ok( CloseHandle( hWriter2 ), "closing 2nd client\n");
ok( CloseHandle( hWriter ), "closing the client\n");
ok( CloseHandle( hSlot ), "closing the mailslot\n");
}
return 0;
}
......
......@@ -130,6 +130,7 @@ NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIB
ULONG options, PVOID ea_buffer, ULONG ea_length )
{
static const WCHAR pipeW[] = {'\\','?','?','\\','p','i','p','e','\\'};
static const WCHAR mailslotW[] = {'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
ANSI_STRING unix_name;
int created = FALSE;
......@@ -166,6 +167,25 @@ NTSTATUS WINAPI NtCreateFile( PHANDLE handle, ACCESS_MASK access, POBJECT_ATTRIB
return io->u.Status;
}
/* check for mailslot */
if (attr->ObjectName->Length > sizeof(mailslotW) &&
!memicmpW( attr->ObjectName->Buffer, mailslotW, sizeof(mailslotW)/sizeof(WCHAR) ))
{
SERVER_START_REQ( open_mailslot )
{
req->access = access & GENERIC_WRITE;
req->sharing = sharing;
req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
wine_server_add_data( req, attr->ObjectName->Buffer + 4,
attr->ObjectName->Length - 4*sizeof(WCHAR) );
io->u.Status = wine_server_call( req );
*handle = reply->handle;
}
SERVER_END_REQ;
return io->u.Status;
}
io->u.Status = wine_nt_to_unix_file_name( attr->ObjectName, &unix_name, disposition,
!(attr->Attributes & OBJ_CASE_INSENSITIVE) );
......@@ -1766,7 +1786,7 @@ NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
'\\','?','?','\\','M','A','I','L','S','L','O','T','\\'};
NTSTATUS ret;
FIXME("%p %08lx %p %p %08lx %08lx %08lx %p\n",
TRACE("%p %08lx %p %p %08lx %08lx %08lx %p\n",
pHandle, DesiredAccess, attr, IoStatusBlock,
CreateOptions, MailslotQuota, MaxMessageSize, TimeOut);
......@@ -1777,7 +1797,18 @@ NTSTATUS WINAPI NtCreateMailslotFile(PHANDLE pHandle, ULONG DesiredAccess,
return STATUS_OBJECT_NAME_INVALID;
}
ret = STATUS_NOT_IMPLEMENTED;
SERVER_START_REQ( create_mailslot )
{
req->max_msgsize = MaxMessageSize;
req->read_timeout = TimeOut->QuadPart / -10000;
req->inherit = (attr->Attributes & OBJ_INHERIT) != 0;
wine_server_add_data( req, attr->ObjectName->Buffer + 4,
attr->ObjectName->Length - 4*sizeof(WCHAR) );
ret = wine_server_call( req );
if( ret == STATUS_SUCCESS )
*pHandle = reply->handle;
}
SERVER_END_REQ;
return ret;
}
......@@ -3241,6 +3241,57 @@ struct duplicate_token_reply
};
struct create_mailslot_request
{
struct request_header __header;
unsigned int max_msgsize;
unsigned int read_timeout;
int inherit;
/* VARARG(name,unicode_str); */
};
struct create_mailslot_reply
{
struct reply_header __header;
obj_handle_t handle;
};
struct open_mailslot_request
{
struct request_header __header;
unsigned int access;
int inherit;
unsigned int sharing;
/* VARARG(name,unicode_str); */
};
struct open_mailslot_reply
{
struct reply_header __header;
obj_handle_t handle;
};
struct set_mailslot_info_request
{
struct request_header __header;
obj_handle_t handle;
unsigned int flags;
unsigned int read_timeout;
};
struct set_mailslot_info_reply
{
struct reply_header __header;
unsigned int max_msgsize;
unsigned int read_timeout;
unsigned int msg_count;
unsigned int next_msgsize;
};
#define MAILSLOT_SET_READ_TIMEOUT 1
enum request
{
REQ_new_process,
......@@ -3428,6 +3479,9 @@ enum request
REQ_adjust_token_privileges,
REQ_get_token_privileges,
REQ_duplicate_token,
REQ_create_mailslot,
REQ_open_mailslot,
REQ_set_mailslot_info,
REQ_NB_REQUESTS
};
......@@ -3620,6 +3674,9 @@ union generic_request
struct adjust_token_privileges_request adjust_token_privileges_request;
struct get_token_privileges_request get_token_privileges_request;
struct duplicate_token_request duplicate_token_request;
struct create_mailslot_request create_mailslot_request;
struct open_mailslot_request open_mailslot_request;
struct set_mailslot_info_request set_mailslot_info_request;
};
union generic_reply
{
......@@ -3810,8 +3867,11 @@ union generic_reply
struct adjust_token_privileges_reply adjust_token_privileges_reply;
struct get_token_privileges_reply get_token_privileges_reply;
struct duplicate_token_reply duplicate_token_reply;
struct create_mailslot_reply create_mailslot_reply;
struct open_mailslot_reply open_mailslot_reply;
struct set_mailslot_info_reply set_mailslot_info_reply;
};
#define SERVER_PROTOCOL_VERSION 164
#define SERVER_PROTOCOL_VERSION 165
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */
......@@ -21,6 +21,7 @@ C_SRCS = \
file.c \
handle.c \
hook.c \
mailslot.c \
main.c \
mapping.c \
mutex.c \
......
......@@ -2272,3 +2272,39 @@ enum message_type
@REPLY
obj_handle_t new_handle; /* duplicated handle */
@END
/* Create a mailslot */
@REQ(create_mailslot)
unsigned int max_msgsize;
unsigned int read_timeout;
int inherit;
VARARG(name,unicode_str); /* mailslot name */
@REPLY
obj_handle_t handle; /* handle to the mailslot */
@END
/* Open an existing mailslot */
@REQ(open_mailslot)
unsigned int access;
int inherit; /* inherit flag */
unsigned int sharing; /* sharing mode */
VARARG(name,unicode_str); /* mailslot name */
@REPLY
obj_handle_t handle; /* handle to the mailslot */
@END
/* Set mailslot information */
@REQ(set_mailslot_info)
obj_handle_t handle; /* handle to the mailslot */
unsigned int flags;
unsigned int read_timeout;
@REPLY
unsigned int max_msgsize;
unsigned int read_timeout;
unsigned int msg_count;
unsigned int next_msgsize;
@END
#define MAILSLOT_SET_READ_TIMEOUT 1
......@@ -288,6 +288,9 @@ DECL_HANDLER(set_global_windows);
DECL_HANDLER(adjust_token_privileges);
DECL_HANDLER(get_token_privileges);
DECL_HANDLER(duplicate_token);
DECL_HANDLER(create_mailslot);
DECL_HANDLER(open_mailslot);
DECL_HANDLER(set_mailslot_info);
#ifdef WANT_REQUEST_HANDLERS
......@@ -479,6 +482,9 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] =
(req_handler)req_adjust_token_privileges,
(req_handler)req_get_token_privileges,
(req_handler)req_duplicate_token,
(req_handler)req_create_mailslot,
(req_handler)req_open_mailslot,
(req_handler)req_set_mailslot_info,
};
#endif /* WANT_REQUEST_HANDLERS */
......
......@@ -2696,6 +2696,49 @@ static void dump_duplicate_token_reply( const struct duplicate_token_reply *req
fprintf( stderr, " new_handle=%p", req->new_handle );
}
static void dump_create_mailslot_request( const struct create_mailslot_request *req )
{
fprintf( stderr, " max_msgsize=%08x,", req->max_msgsize );
fprintf( stderr, " read_timeout=%08x,", req->read_timeout );
fprintf( stderr, " inherit=%d,", req->inherit );
fprintf( stderr, " name=" );
dump_varargs_unicode_str( cur_size );
}
static void dump_create_mailslot_reply( const struct create_mailslot_reply *req )
{
fprintf( stderr, " handle=%p", req->handle );
}
static void dump_open_mailslot_request( const struct open_mailslot_request *req )
{
fprintf( stderr, " access=%08x,", req->access );
fprintf( stderr, " inherit=%d,", req->inherit );
fprintf( stderr, " sharing=%08x,", req->sharing );
fprintf( stderr, " name=" );
dump_varargs_unicode_str( cur_size );
}
static void dump_open_mailslot_reply( const struct open_mailslot_reply *req )
{
fprintf( stderr, " handle=%p", req->handle );
}
static void dump_set_mailslot_info_request( const struct set_mailslot_info_request *req )
{
fprintf( stderr, " handle=%p,", req->handle );
fprintf( stderr, " flags=%08x,", req->flags );
fprintf( stderr, " read_timeout=%08x", req->read_timeout );
}
static void dump_set_mailslot_info_reply( const struct set_mailslot_info_reply *req )
{
fprintf( stderr, " max_msgsize=%08x,", req->max_msgsize );
fprintf( stderr, " read_timeout=%08x,", req->read_timeout );
fprintf( stderr, " msg_count=%08x,", req->msg_count );
fprintf( stderr, " next_msgsize=%08x", req->next_msgsize );
}
static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_new_process_request,
(dump_func)dump_get_new_process_info_request,
......@@ -2882,6 +2925,9 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_adjust_token_privileges_request,
(dump_func)dump_get_token_privileges_request,
(dump_func)dump_duplicate_token_request,
(dump_func)dump_create_mailslot_request,
(dump_func)dump_open_mailslot_request,
(dump_func)dump_set_mailslot_info_request,
};
static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
......@@ -3070,6 +3116,9 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_adjust_token_privileges_reply,
(dump_func)dump_get_token_privileges_reply,
(dump_func)dump_duplicate_token_reply,
(dump_func)dump_create_mailslot_reply,
(dump_func)dump_open_mailslot_reply,
(dump_func)dump_set_mailslot_info_reply,
};
static const char * const req_names[REQ_NB_REQUESTS] = {
......@@ -3258,6 +3307,9 @@ static const char * const req_names[REQ_NB_REQUESTS] = {
"adjust_token_privileges",
"get_token_privileges",
"duplicate_token",
"create_mailslot",
"open_mailslot",
"set_mailslot_info",
};
/* ### make_requests end ### */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment