ObjFW
Instance Methods | Class Methods | Properties | List of all members
OFSequencedPacketSocket Class Reference

A base class for sequenced packet sockets. More...

#import <ObjFW/OFSequencedPacketSocket.h>

Inheritance diagram for OFSequencedPacketSocket:
Inheritance graph
[legend]
Collaboration diagram for OFSequencedPacketSocket:
Collaboration graph
[legend]

Instance Methods

(size_t) - receiveIntoBuffer:length:
 Receives a packet and stores it into the specified buffer. More...
 
(void) - asyncReceiveIntoBuffer:length:
 Asynchronously receives a packet and stores it into the specified buffer. More...
 
(void) - asyncReceiveIntoBuffer:length:runLoopMode:
 Asynchronously receives a packet and stores it into the specified buffer. More...
 
(void) - asyncReceiveIntoBuffer:length:block:
 Asynchronously receives a packet and stores it into the specified buffer. More...
 
(void) - asyncReceiveIntoBuffer:length:runLoopMode:block:
 Asynchronously receives a packet and stores it into the specified buffer. More...
 
(void) - sendBuffer:length:
 Sends the specified packet. More...
 
(void) - asyncSendData:
 Asynchronously sends the specified packet. More...
 
(void) - asyncSendData:runLoopMode:
 Asynchronously sends the specified packet. More...
 
(void) - asyncSendData:block:
 Asynchronously sends the specified packet. More...
 
(void) - asyncSendData:runLoopMode:block:
 Asynchronously sends the specified packet. More...
 
(void) - listenWithBacklog:
 Listen on the socket. More...
 
(void) - listen
 Listen on the socket.
 
(instancetype) - accept
 Accept an incoming connection. More...
 
(void) - asyncAccept
 Asynchronously accept an incoming connection.
 
(void) - asyncAcceptWithRunLoopMode:
 Asynchronously accept an incoming connection. More...
 
(void) - asyncAcceptWithBlock:
 Asynchronously accept an incoming connection. More...
 
(void) - asyncAcceptWithRunLoopMode:block:
 Asynchronously accept an incoming connection. More...
 
(void) - cancelAsyncRequests
 Cancels all pending asynchronous requests on the socket.
 
(void) - close
 Closes the socket so that it can neither receive nor send any more datagrams.
 
- Instance Methods inherited from OFObject
(instancetype) - init
 Initializes an already allocated object. More...
 
(nullable OFMethodSignature *) - methodSignatureForSelector:
 Returns the method signature for the specified selector. More...
 
(void) - dealloc
 Deallocates the object. More...
 
(void) - performSelector:afterDelay:
 Performs the specified selector after the specified delay. More...
 
(void) - performSelector:withObject:afterDelay:
 Performs the specified selector with the specified object after the specified delay. More...
 
(void) - performSelector:withObject:withObject:afterDelay:
 Performs the specified selector with the specified objects after the specified delay. More...
 
(void) - performSelector:withObject:withObject:withObject:afterDelay:
 Performs the specified selector with the specified objects after the specified delay. More...
 
(void) - performSelector:withObject:withObject:withObject:withObject:afterDelay:
 Performs the specified selector with the specified objects after the specified delay. More...
 
(void) - performSelector:onThread:waitUntilDone:
 Performs the specified selector on the specified thread. More...
 
(void) - performSelector:onThread:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified object. More...
 
(void) - performSelector:onThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified objects. More...
 
(void) - performSelector:onThread:withObject:withObject:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified objects. More...
 
(void) - performSelector:onThread:withObject:withObject:withObject:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified objects. More...
 
(void) - performSelectorOnMainThread:waitUntilDone:
 Performs the specified selector on the main thread. More...
 
(void) - performSelectorOnMainThread:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified object. More...
 
(void) - performSelectorOnMainThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified objects. More...
 
(void) - performSelectorOnMainThread:withObject:withObject:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified objects. More...
 
(void) - performSelectorOnMainThread:withObject:withObject:withObject:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified objects. More...
 
(void) - performSelector:onThread:afterDelay:
 Performs the specified selector on the specified thread after the specified delay. More...
 
(void) - performSelector:onThread:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified object after the specified delay. More...
 
(void) - performSelector:onThread:withObject:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified objects after the specified delay. More...
 
(void) - performSelector:onThread:withObject:withObject:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified objects after the specified delay. More...
 
(void) - performSelector:onThread:withObject:withObject:withObject:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified objects after the specified delay. More...
 
(nullable id- forwardingTargetForSelector:
 This method is called when resolveClassMethod: or resolveInstanceMethod: returned false. It should return a target to which the message should be forwarded. More...
 
(void) - doesNotRecognizeSelector:
 Handles messages which are not understood by the receiver. More...
 
- Instance Methods inherited from <OFObject>
(unsigned long) - hash
 Returns a 32 bit hash for the object. More...
 
(unsigned int) - retainCount
 Returns the retain count. More...
 
(bool) - isProxy
 Returns whether the object is a proxy object. More...
 
(bool) - allowsWeakReference
 Returns whether the object allows weak references. More...
 
(bool) - isKindOfClass:
 Returns a boolean whether the object of the specified kind. More...
 
(bool) - isMemberOfClass:
 Returns a boolean whether the object is a member of the specified class. More...
 
(bool) - respondsToSelector:
 Returns a boolean whether the object responds to the specified selector. More...
 
(nullable IMP- methodForSelector:
 Returns the implementation for the specified selector. More...
 
(nullable id- performSelector:
 Performs the specified selector. More...
 
(nullable id- performSelector:withObject:
 Performs the specified selector with the specified object. More...
 
(nullable id- performSelector:withObject:withObject:
 Performs the specified selector with the specified objects. More...
 
(nullable id- performSelector:withObject:withObject:withObject:
 Performs the specified selector with the specified objects. More...
 
(nullable id- performSelector:withObject:withObject:withObject:withObject:
 Performs the specified selector with the specified objects. More...
 
(bool) - isEqual:
 Checks two objects for equality. More...
 
(instancetype) - retain
 Increases the retain count. More...
 
(void) - release
 Decreases the retain count. More...
 
(instancetype) - autorelease
 Adds the object to the topmost autorelease pool of the thread's autorelease pool stack. More...
 
(instancetype) - self
 Returns the receiver. More...
 
(bool) - retainWeakReference
 Retain a weak reference to this object. More...
 
- Instance Methods inherited from <OFCopying>
(id- copy
 Copies the object. More...
 

Class Methods

(instancetype) + socket
 Returns a new, autoreleased OFSequencedPacketSocket. More...
 
- Class Methods inherited from OFObject
(void) + load
 A method which is called once when the class is loaded into the runtime. More...
 
(void) + unload
 A method which is called when the class is unloaded from the runtime. More...
 
(void) + initialize
 A method which is called the moment before the first call to the class is being made. More...
 
(instancetype) + alloc
 Allocates memory for an instance of the class and sets up the memory pool for the object. More...
 
(instancetype) + new
 Calls alloc on self and then init on the returned object. More...
 
(Class+ class
 Returns the class. More...
 
(OFString *) + className
 Returns the name of the class as a string. More...
 
(bool) + isSubclassOfClass:
 Returns a boolean whether the class is a subclass of the specified class. More...
 
(nullable Class+ superclass
 Returns the superclass of the class. More...
 
(bool) + instancesRespondToSelector:
 Checks whether instances of the class respond to a given selector. More...
 
(bool) + conformsToProtocol:
 Checks whether the class conforms to a given protocol. More...
 
(nullable IMP+ instanceMethodForSelector:
 Returns the implementation of the instance method for the specified selector. More...
 
(nullable OFMethodSignature *) + instanceMethodSignatureForSelector:
 Returns the method signature of the instance method for the specified selector. More...
 
(OFString *) + description
 Returns a description for the class, which is usually the class name. More...
 
(nullable IMP+ replaceClassMethod:withMethodFromClass:
 Replaces a class method with a class method from another class. More...
 
(nullable IMP+ replaceInstanceMethod:withMethodFromClass:
 Replaces an instance method with an instance method from another class. More...
 
(void) + inheritMethodsFromClass:
 Adds all methods from the specified class to the class that is the receiver. More...
 
(bool) + resolveClassMethod:
 Try to resolve the specified class method. More...
 
(bool) + resolveInstanceMethod:
 Try to resolve the specified instance method. More...
 
(id+ copy
 Returns the class. More...
 

Properties

bool canBlock
 Whether the socket can block. More...
 
bool listening
 Whether the socket is a listening socket.
 
const of_socket_address_tremoteAddress
 The remote address. More...
 
id< OFSequencedPacketSocketDelegatedelegate
 The delegate for asynchronous operations on the socket. More...
 
- Properties inherited from OFObject
OFStringclassName
 The name of the object's class.
 
OFStringdescription
 A description for the object. More...
 
OFStringstringBySerializing
 The object serialized as a string.
 
- Properties inherited from <OFReadyForReadingObserving>
int fileDescriptorForReading
 The file descriptor for reading that should be checked by the OFKernelEventObserver.
 
- Properties inherited from <OFReadyForWritingObserving>
int fileDescriptorForWriting
 The file descriptor for writing that should be checked by the OFKernelEventObserver.
 

Detailed Description

A base class for sequenced packet sockets.

Warning
Even though the OFCopying protocol is implemented, it does not return an independent copy of the socket, but instead retains it. This is so that the socket can be used as a key for a dictionary, so context can be associated with a socket. Using a socket in more than one thread at the same time is not thread-safe, even if copy was called to create one "instance" for every thread!

Method Documentation

◆ accept

- (instancetype) accept

Accept an incoming connection.

Returns
An autoreleased sequenced packet socket for the accepted connection.

◆ asyncAcceptWithBlock:

- (void) asyncAcceptWithBlock: (of_sequenced_packet_socket_async_accept_block_t block

Asynchronously accept an incoming connection.

Parameters
blockThe block to execute when a new connection has been accepted. Returns whether the next incoming connection should be accepted by the specified block as well.

◆ asyncAcceptWithRunLoopMode:

- (void) asyncAcceptWithRunLoopMode: (of_run_loop_mode_t runLoopMode

Asynchronously accept an incoming connection.

Parameters
runLoopModeThe run loop mode in which to perform the async accept

◆ asyncAcceptWithRunLoopMode:block:

Asynchronously accept an incoming connection.

Parameters
runLoopModeThe run loop mode in which to perform the async accept
blockThe block to execute when a new connection has been accepted. Returns whether the next incoming connection should be accepted by the specified block as well.

◆ asyncReceiveIntoBuffer:length:

- (void) asyncReceiveIntoBuffer: (void *)  buffer
length: (size_t)  length 

Asynchronously receives a packet and stores it into the specified buffer.

If the buffer is too small, the receive operation fails.

Parameters
bufferThe buffer to write the packet to
lengthThe length of the buffer

◆ asyncReceiveIntoBuffer:length:block:

- (void) asyncReceiveIntoBuffer: (void *)  buffer
length: (size_t)  length
block: (of_sequenced_packet_socket_async_receive_block_t block 

Asynchronously receives a packet and stores it into the specified buffer.

If the buffer is too small, the receive operation fails.

Parameters
bufferThe buffer to write the packet to
lengthThe length of the buffer
blockThe block to call when the packet has been received. If the block returns true, it will be called again with the same buffer and maximum length when more packets have been received. If you want the next method in the queue to handle the packet received next, you need to return false from the method.

◆ asyncReceiveIntoBuffer:length:runLoopMode:

- (void) asyncReceiveIntoBuffer: (void *)  buffer
length: (size_t)  length
runLoopMode: (of_run_loop_mode_t runLoopMode 

Asynchronously receives a packet and stores it into the specified buffer.

If the buffer is too small, the receive operation fails.

Parameters
bufferThe buffer to write the packet to
lengthThe length of the buffer
runLoopModeThe run loop mode in which to perform the async receive

◆ asyncReceiveIntoBuffer:length:runLoopMode:block:

- (void) asyncReceiveIntoBuffer: (void *)  buffer
length: (size_t)  length
runLoopMode: (of_run_loop_mode_t runLoopMode
block: (of_sequenced_packet_socket_async_receive_block_t block 

Asynchronously receives a packet and stores it into the specified buffer.

If the buffer is too small, the receive operation fails.

Parameters
bufferThe buffer to write the packet to
lengthThe length of the buffer
runLoopModeThe run loop mode in which to perform the async receive
blockThe block to call when the packet has been received. If the block returns true, it will be called again with the same buffer and maximum length when more packets have been received. If you want the next method in the queue to handle the packet received next, you need to return false from the method.

◆ asyncSendData:

- (void) asyncSendData: (OFData *)  data

Asynchronously sends the specified packet.

Parameters
dataThe data to send as a packet

◆ asyncSendData:block:

Asynchronously sends the specified packet.

Parameters
dataThe data to send as a packet
blockThe block to call when the packet has been sent. It should return the data for the next send with the same callback or nil if it should not repeat.

◆ asyncSendData:runLoopMode:

- (void) asyncSendData: (OFData *)  data
runLoopMode: (of_run_loop_mode_t runLoopMode 

Asynchronously sends the specified packet.

Parameters
dataThe data to send as a packet
runLoopModeThe run loop mode in which to perform the async send

◆ asyncSendData:runLoopMode:block:

- (void) asyncSendData: (OFData *)  data
runLoopMode: (of_run_loop_mode_t runLoopMode
block: (of_sequenced_packet_socket_async_send_data_block_t block 

Asynchronously sends the specified packet.

Parameters
dataThe data to send as a packet
runLoopModeThe run loop mode in which to perform the async send
blockThe block to call when the packet has been sent. It should return the data for the next send with the same callback or nil if it should not repeat.

◆ listenWithBacklog:

- (void) listenWithBacklog: (int)  backlog

Listen on the socket.

Parameters
backlogMaximum length for the queue of pending connections.

◆ receiveIntoBuffer:length:

- (size_t) receiveIntoBuffer: (void *)  buffer
length: (size_t)  length 

Receives a packet and stores it into the specified buffer.

If the buffer is too small, the receive operation fails.

Parameters
bufferThe buffer to write the packet to
lengthThe length of the buffer
Returns
The length of the received packet

◆ sendBuffer:length:

- (void) sendBuffer: (const void *)  buffer
length: (size_t)  length 

Sends the specified packet.

Parameters
bufferThe buffer to send as a packet
lengthThe length of the buffer

◆ socket

+ (instancetype) socket

Returns a new, autoreleased OFSequencedPacketSocket.

Returns
A new, autoreleased OFSequencedPacketSocket

Property Documentation

◆ canBlock

- (bool) canBlock
readwritenonatomicassign

Whether the socket can block.

By default, a socket can block.

◆ delegate

- (id<OFSequencedPacketSocketDelegate>) delegate
readwriteatomic

The delegate for asynchronous operations on the socket.

Note
The delegate is retained for as long as asynchronous operations are still ongoing.

◆ remoteAddress

- (const of_socket_address_t *) remoteAddress
readnonatomicassign

The remote address.

Note
This only works for accepted sockets!

The documentation for this class was generated from the following files: