@@ -15,9 +15,6 @@ @interface TcpSocketClient()
1515{
1616@private
1717 GCDAsyncSocket *_tcpSocket;
18- NSMutableDictionary <NSNumber *, RCTResponseSenderBlock> *_pendingSends;
19- NSLock *_lock;
20- long _sendTag;
2118}
2219
2320- (id )initWithClientId : (NSNumber *)clientID andConfig : (id <SocketClientDelegate>)aDelegate ;
@@ -43,8 +40,6 @@ - (id)initWithClientId:(NSNumber *)clientID andConfig:(id<SocketClientDelegate>)
4340 if (self) {
4441 _id = clientID;
4542 _clientDelegate = aDelegate;
46- _pendingSends = [NSMutableDictionary dictionary ];
47- _lock = [[NSLock alloc ] init ];
4843 _tcpSocket = tcpSocket;
4944 [_tcpSocket setUserData: clientID];
5045 }
@@ -134,58 +129,24 @@ - (BOOL)listen:(NSString *)host port:(int)port error:(NSError **)error
134129 return isListening;
135130}
136131
137- - (void )setPendingSend : (RCTResponseSenderBlock)callback forKey : (NSNumber *)key
138- {
139- [_lock lock ];
140- @try {
141- [_pendingSends setObject: callback forKey: key];
142- }
143- @finally {
144- [_lock unlock ];
145- }
146- }
147-
148- - (RCTResponseSenderBlock)getPendingSend : (NSNumber *)key
149- {
150- [_lock lock ];
151- @try {
152- return [_pendingSends objectForKey: key];
153- }
154- @finally {
155- [_lock unlock ];
156- }
157- }
158-
159- - (void )dropPendingSend : (NSNumber *)key
160- {
161- [_lock lock ];
162- @try {
163- [_pendingSends removeObjectForKey: key];
164- }
165- @finally {
166- [_lock unlock ];
167- }
168- }
169-
170132- (void )socket : (GCDAsyncSocket *)sock didWriteDataWithTag : (long )msgTag
171133{
172134 NSNumber * tagNum = [NSNumber numberWithLong: msgTag];
173- RCTResponseSenderBlock callback = [self getPendingSend: tagNum];
135+ RCTResponseSenderBlock callback = [_clientDelegate getPendingSend: tagNum];
174136 if (callback) {
175137 callback (@[]);
176- [self dropPendingSend: tagNum];
138+ [_clientDelegate dropPendingSend: tagNum];
177139 }
178140}
179141
180142- (void ) writeData : (NSData *)data
181143 callback : (RCTResponseSenderBlock)callback
182144{
145+ NSNumber *sendTag = [_clientDelegate getNextTag ];
183146 if (callback) {
184- [self setPendingSend: callback forKey: @(_sendTag) ];
147+ [_clientDelegate setPendingSend: callback forKey: sendTag ];
185148 }
186- [_tcpSocket writeData: data withTimeout: -1 tag: _sendTag];
187-
188- _sendTag++;
149+ [_tcpSocket writeData: data withTimeout: -1 tag: sendTag.longValue];
189150
190151 [_tcpSocket readDataWithTimeout: -1 tag: _id.longValue];
191152}
0 commit comments