Jano Svitok created THRIFT-5125:
-----------------------------------
Summary: Swift issues
Key: THRIFT-5125
URL: https://issues.apache.org/jira/browse/THRIFT-5125
Project: Thrift
Issue Type: Bug
Components: Swift - Compiler, Swift - Library
Affects Versions: 0.14.0
Reporter: Jano Svitok
TL;DR: Swift server does not work using present code.
I'm writing thrift server in swift running on iOS. For reference, I'm using
SocketServer, MultiplexedProcessor with BinaryProtocol over FramedTransport.
Client is in Java, and we already have Java server running on Android.
Note that I'm new to swift, iOS and Apple world, so I may not understand
everything.
During development I've found these issues:
# _TSocketServer.init()_: Conversion of port: Int to sin_port: in_port_t (that
is UInt16) fails with "... _is not representable as_...".
UInt16(truncatingIfNeeded:).bigEndian is needed instead of port.bigEndian
#
[https://github.com/apache/thrift/blob/master/lib/swift/Sources/TSocketServer.swift#L85]
tries to deallocate _address,_ due to _nil_ deallocator, equivalent to
_kCFAllocatorDefault_. Proper deallocator seems to be _kCFAllocatorNone_.
# According to
[https://developer.apple.com/documentation/foundation/nsfilehandle/1413309-acceptconnectioninbackgroundandn?language=objc]
(see last paragraph),
_socketFileHandle.acceptConnectionInBackgroundAndNotify()_ should be called
again at the end of _TSocketServer.connectionAccepted()_. Old cocoa code does
it.
# _TSocketServer.connectionAccepted()_ tries to read from the listening socket
instead of client socket, resulting in "Socket not connected" error. Client
socket handle is in
_notification.userInfo[NSFileHandleNotificationFileHandleItem]_
# TSocketServer.handleClientConnection handles only one message. Loop is
missing around _try processor.process()_. I.e. _while true \{ try
processor.process }_
# It is not possible to pass _TFramedTransport_ to _TSocketServer_
# _TSocketServer.serviceHandle_ is not used anymore
# _TFramedTransport.flush_ is not called anywhere; therefore, the message is
never sent. _outProtocol.transport.flush_ should be added to generated
processors after _outProtocol.writeMessageEnd_, and also after writeException.
# _TFramedTransport.remainingBytes_ are not reset anywhere, thus the header of
second and further messages are not processed properly
I will create pull request after I clean up my patches.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)