Clapkit
Loading...
Searching...
No Matches
ckNetBaseSocket.h
Go to the documentation of this file.
1/*
2 *
3 * Clapkit
4 * ----------------------------------------------------------------------
5 * A wrapper for creating a 'generalized' app for Classic MacOS
6 * that (hopefully) can be ported easily to other platforms.
7 *
8 * CKNetBaseSocket
9 * ----------------------------------------------------------------------
10 * Implements the base socket for CKNetClient and CKNetServer
11 *
12 */
13
14#include "ckObject.h"
15#include "ckTypes.h"
16#include <Devices.h>
17#include <MacTCP.h>
18
19pascal void CKNBSNotify(StreamPtr stream, unsigned short eventCode, Ptr userDataPtr, unsigned short terminReason, struct ICMPReport* icmpMsg);
20void CKNBSIOCompletion(TCPiopb* iopb);
21
22extern TCPNotifyUPP ckgNotifyUPP;
23extern TCPIOCompletionUPP ckgIOCompletionUPP;
24
30 public:
31 short csCode = 0;
32 bool result = false;
33 TCPiopb* pb = nullptr;
34 bool countsPending = false;
35 bool pbFromNewPtr = false;
36 bool isWritten = false;
37 bool isRead = false;
38};
39
41 public:
42 unsigned short eventCode = 0;
43 unsigned short terminReason = 0;
44 ICMPReport* icmpMsg = nullptr;
45 bool isWritten = false;
46 bool isRead = false;
47};
48
53class CKNetBaseSocket : public CKObject {
54
55 public:
58
59 virtual void Close();
60 void SetBufferSize(UInt16 size) {
61 if (this->__stream) {
62 return;
63 }
64 this->__mactcpBufferSize = size;
65 }
66 UInt16 GetBufferSize() {
67 return this->__mactcpBufferSize;
68 }
69
70 virtual void Loop();
71
72 protected:
76
77 friend pascal void CKNBSNotify(StreamPtr, unsigned short, Ptr, unsigned short, struct ICMPReport*);
78 void __postNotifyEvent(unsigned short eventCode, unsigned short terminReason, struct ICMPReport* icmpMsg);
79
80 friend void CKNBSIOCompletion(TCPiopb* iopb);
81 void __postIOCompletionEvent(unsigned short csCode, bool result, TCPiopb* pb, bool countsPending, bool pbFromNewPtr);
82
83 protected:
84 UInt16 __mactcpBufferSize = 8192;
86 StreamPtr __stream = 0;
87 bool __hasStream = false;
88 bool __isConnected = false;
90
91 private:
92 bool __hasIntEvents = false;
93 bool __hasNotifyEvents = false;
94 bool __hasIncomingData = false;
95 bool __hasDisconnected = false;
96 CKNetBaseSocketEvtFromInterrupt __intEvents[32];
97 CKNetBaseSocketNotifyEvt __notifyEvents[32];
98 int __intEventsWriteIdx = 0;
99 int __intEventsReadIdx = 0;
100 int __notifyEventsWriteIdx = 0;
101 int __notifyEventsReadIdx = 0;
102 bool __waitingForClose = false;
103};
TCPIOCompletionUPP ckgIOCompletionUPP
Definition ckNetBaseSocket.cpp:23
pascal void CKNBSNotify(StreamPtr stream, unsigned short eventCode, Ptr userDataPtr, unsigned short terminReason, struct ICMPReport *icmpMsg)
Definition ckNetBaseSocket.cpp:371
void CKNBSIOCompletion(TCPiopb *iopb)
Definition ckNetBaseSocket.cpp:380
TCPNotifyUPP ckgNotifyUPP
Definition ckNetBaseSocket.cpp:22
Defines the base of all TCP client/server sockets.
Definition ckNetBaseSocket.h:53
void SetBufferSize(UInt16 size)
Definition ckNetBaseSocket.h:60
virtual void Close()
Definition ckNetBaseSocket.cpp:47
~CKNetBaseSocket()
Definition ckNetBaseSocket.cpp:35
bool __isConnected
Definition ckNetBaseSocket.h:88
StreamPtr __stream
Definition ckNetBaseSocket.h:86
void __postNotifyEvent(unsigned short eventCode, unsigned short terminReason, struct ICMPReport *icmpMsg)
Definition ckNetBaseSocket.cpp:188
CKNetBaseSocket()
Definition ckNetBaseSocket.cpp:25
Ptr __mactcpBuffer
Definition ckNetBaseSocket.h:85
UInt16 __pendingAsyncOps
Definition ckNetBaseSocket.h:89
UInt16 __mactcpBufferSize
Definition ckNetBaseSocket.h:84
CKError __closeStream()
Definition ckNetBaseSocket.cpp:51
bool __hasStream
Definition ckNetBaseSocket.h:87
void __postIOCompletionEvent(unsigned short csCode, bool result, TCPiopb *pb, bool countsPending, bool pbFromNewPtr)
Definition ckNetBaseSocket.cpp:219
friend void CKNBSIOCompletion(TCPiopb *iopb)
Definition ckNetBaseSocket.cpp:380
friend pascal void CKNBSNotify(StreamPtr, unsigned short, Ptr, unsigned short, struct ICMPReport *)
Definition ckNetBaseSocket.cpp:371
CKError __releaseStream()
Definition ckNetBaseSocket.cpp:157
UInt16 GetBufferSize()
Definition ckNetBaseSocket.h:66
virtual void Loop()
Definition ckNetBaseSocket.cpp:236
CKError __openStream()
Definition ckNetBaseSocket.cpp:97
Defines the base class for all controls and objects.
Definition ckObject.h:43
int32_t CKError
Return type for functions that might return an error. Also see: CKPass and CKErrorCode.
Definition ckTypes.h:27
Defines a TCP event that's coming from the interrupt, to be added to the event handling queue.
Definition ckNetBaseSocket.h:29
bool isRead
Definition ckNetBaseSocket.h:37
bool isWritten
Definition ckNetBaseSocket.h:36
bool countsPending
Definition ckNetBaseSocket.h:34
short csCode
Definition ckNetBaseSocket.h:31
bool result
Definition ckNetBaseSocket.h:32
TCPiopb * pb
Definition ckNetBaseSocket.h:33
bool pbFromNewPtr
Definition ckNetBaseSocket.h:35
Definition ckNetBaseSocket.h:40
unsigned short eventCode
Definition ckNetBaseSocket.h:42
unsigned short terminReason
Definition ckNetBaseSocket.h:43
ICMPReport * icmpMsg
Definition ckNetBaseSocket.h:44
bool isRead
Definition ckNetBaseSocket.h:46
bool isWritten
Definition ckNetBaseSocket.h:45