-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSqSocket.class.st
108 lines (90 loc) · 2.73 KB
/
SqSocket.class.st
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"
SqSocket is the C structure stored as the handle in an open {{gtClass:Socket}}.
"
Class {
#name : #SqSocket,
#superclass : #FFIExternalStructure,
#classVars : [
'OFFSET_PRIVATESOCKETPTR',
'OFFSET_SESSIONID',
'OFFSET_SOCKETTYPE'
],
#category : #'GToolkit-Utility-File'
}
{ #category : #accessing }
SqSocket class >> fieldsDesc [
"Retrieved from plugins/SocketPlugin/include/common/SocketPlugin.h 2022-02-05"
"self rebuildFieldAccessors"
^ #(
int sessionID
int socketType
SqPrivateSocket *privateSocketPtr
)
]
{ #category : #accessing }
SqSocket >> fileDescriptor [
"Answer the receiver's file descriptor"
^ self privateSocketPtr s
]
{ #category : #'close on exec' }
SqSocket >> getCloseOnExec [
"Get the CLOEXEC bit for the receiver"
| result |
"Windows doesn't transfer open file descriptors"
OSPlatform current isWindows ifTrue: [ ^ true ].
result := LibC uniqueInstance
fcntl: self fileDescriptor
_: 1 "F_GETFD".
self assert: [ result ~= -1 ]
description: 'Unable to retrieve CLOEXEC'.
^ (result bitAnd: 1) = 1
]
{ #category : #'accessing - structure variables' }
SqSocket >> privateSocketPtr [
"This method was automatically generated"
^SqPrivateSocket fromHandle: (handle pointerAt: OFFSET_PRIVATESOCKETPTR)
]
{ #category : #'accessing - structure variables' }
SqSocket >> privateSocketPtr: anObject [
"This method was automatically generated"
handle pointerAt: OFFSET_PRIVATESOCKETPTR put: anObject getHandle.
]
{ #category : #'accessing - structure variables' }
SqSocket >> sessionID [
"This method was automatically generated"
^handle signedLongAt: OFFSET_SESSIONID
]
{ #category : #'accessing - structure variables' }
SqSocket >> sessionID: anObject [
"This method was automatically generated"
handle signedLongAt: OFFSET_SESSIONID put: anObject
]
{ #category : #'close on exec' }
SqSocket >> setCloseOnExec: aBoolean [
"Set/Clear the CLOEXEC bit on the receiver"
| status |
"Ignore on Windows: sockets aren't transferred to subprocesses"
OSPlatform current isWindows ifTrue: [ ^ self ].
status := LibC uniqueInstance
fcntl: self fileDescriptor
_: 2 "F_SETFD"
_: (aBoolean ifTrue: [ 1 ] ifFalse: [ 0 ]).
self assert: [ status ~= -1 ]
description: 'fcntl() failed'.
]
{ #category : #initialization }
SqSocket >> setHandle: aHandle [
self assert: [ aHandle isNotNil ]
description: 'SqSocket requires an open socket handle'.
^ super setHandle: aHandle.
]
{ #category : #'accessing - structure variables' }
SqSocket >> socketType [
"This method was automatically generated"
^handle signedLongAt: OFFSET_SOCKETTYPE
]
{ #category : #'accessing - structure variables' }
SqSocket >> socketType: anObject [
"This method was automatically generated"
handle signedLongAt: OFFSET_SOCKETTYPE put: anObject
]