ObjFW  Artifact [dc54bd8b6a]

Artifact dc54bd8b6a719a944a99495d9a4927bd34408ab36edf336dc8c1b70d75cf1a21:

  • File src/OFTCPSocket.h — part of check-in [c83137e7cd] at 2008-12-11 13:43:35 on branch trunk — Remove - close from OFStream protocol.
    The reason is that closing a file isn't too useful, because an OFFile
    object can't be reused, whereas an OFTCPSocket can. So only the
    OFTCPSocket should have closed. Plus, we don't need to handle the case
    that someone tried to read from / write to a closed OFFile. (user: js, size: 1622) [annotate] [blame] [check-ins using]

/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>

#import <sys/types.h>
#import <sys/socket.h>
#import <netdb.h>

#import "OFObject.h"
#import "OFStream.h"

/**
 * The OFTCPSocket class provides functions to create and use sockets.
 */
@interface OFTCPSocket: OFObject <OFStream>
{
	int sock;
	struct sockaddr *saddr;
	socklen_t saddr_len;
}

/**
 * Initializes an already allocated OFTCPSocket.
 *
 * \return An initialized OFTCPSocket
 */
- init;

- free;
- setSocket: (int)socket;
- setSocketAddress: (struct sockaddr*)sockaddr
	withLength: (socklen_t)len;

/**
 * Connect the OFTCPSocket to the specified destination.
 *
 * \param host The host or IP to connect to
 * \param port The port of the host to connect to
 */
- connectTo: (const char*)host
     onPort: (uint16_t)port;

/**
 * Bind socket to the specified address and port.
 *
 * \param host The host or IP to bind to
 * \param port The port to bind to
 * \param protocol The protocol to use (AF_INET or AF_INET6)
 */
-    bindOn: (const char*)host
   withPort: (uint16_t)port
  andFamily: (int)family;

/**
 * Listen on the socket.
 *
 * \param backlog Maximum length for the queue of pending connections.
 */
- listenWithBackLog: (int)backlog;

/**
 * Listen on the socket.
 */
- listen;

/**
 * Accept an incoming connection.
 */
- (OFTCPSocket*)accept;

/**
 * Closes the socket.
 */
- close;
@end