source: golgotha/src/max_plugin/maxcomm.cc @ 484

Last change on this file since 484 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "maxcomm.hh"
10
11
12int m1_mail_slot_class::create(const i4_const_str &name)
13//{{{
14{
15  char buf[256];
16  slot = CreateMailslot(i4_os_string(name,buf,sizeof(buf)),    // mail slot name
17                        0,                     // maximum message size (0 == NO_LIMIT)
18                        MAILSLOT_WAIT_FOREVER, // read timeout status
19                        0);                    // security attributes
20
21  if (slot == INVALID_HANDLE_VALUE)
22    return 0;
23
24  return 1;
25}
26//}}}
27
28
29int m1_mail_slot_class::open(const i4_const_str &name)
30//{{{
31{
32  char buf[256];
33  slot = CreateFile(i4_os_string(name,buf,sizeof(buf)),    // mail slot name
34                    GENERIC_WRITE,         // needs GENERIC_WRITE to send to slot
35                    FILE_SHARE_READ,       // required for mail slots
36                    0,                     // secutiry attributes
37                    OPEN_EXISTING,         // find named slot
38                    FILE_ATTRIBUTE_NORMAL,
39                    0);                    // template file to grab attributes
40
41  if (slot == INVALID_HANDLE_VALUE)
42    return 0;
43
44  return 1;
45}
46//}}}
47
48
49int m1_mail_slot_class::read_ready()
50//{{{
51{
52  w32 maxsize = 0;
53  w32 size, number;
54  int result;
55
56  result = GetMailslotInfo(slot,     // mail slot handle
57                           &maxsize, //
58                           &size,
59                           &number,
60                           0);
61
62  if (!result)
63    return 0;
64
65  return (number>0);
66}
67//}}}
68
69
70w32 m1_mail_slot_class::write(char *buff, w32 size)
71//{{{
72{
73  w32 r;
74  int result;
75
76  result = WriteFile(slot,
77                     buff,
78                     size,
79                     &r,
80                     0);
81 
82  if (!result)
83  {
84    slot = INVALID_HANDLE_VALUE;
85    return 0;
86  }
87
88  return r;
89}
90//}}}
91
92
93w32 m1_mail_slot_class::read(char *buff, w32 maxsize)
94//{{{
95{
96  w32 size, number, r;
97  int result;
98
99  result = GetMailslotInfo(slot, &maxsize, &size, &number, 0);
100 
101  if (!result)
102    return 0;
103
104  result = ReadFile(slot, buff, size, &r, 0);
105 
106  if (!result)
107    return 0;
108
109  return r;
110}
111//}}}
112
113
114//{{{ Emacs Locals
115// Local Variables:
116// folded-file: t
117// End:
118//}}}
Note: See TracBrowser for help on using the repository browser.