- struct hostent *hostent;
- struct servent *servent;
- char *endptr;
- long port_long;
- uint16_t port_short;
-
- addr->sin_family = AF_INET;
-
- hostent = gethostbyname (host);
- if (hostent == NULL)
- {
- fprintf (stderr, "Error: Lookup failed for host %s: %s\n",
- host, hstrerror (h_errno));
- return TTT_STATUS_FAILURE;
- }
- memcpy (&addr->sin_addr.s_addr, hostent->h_addr_list[0],
- sizeof (addr->sin_addr.s_addr));
-
- assert (*port != '\0');
- port_long = strtol (port, &endptr, 10);
- if (*endptr == '\0')
- {
- /* Numeric port*/
- if (port_long <= 0 || port_long >= (1 << 16)) {
- fprintf (stderr, "Error: Port %ld out of range.\n", port_long);
- return TTT_STATUS_FAILURE;
- }
- port_short = port_long;
- addr->sin_port = htons (port_short);
- } else {
- /* Named port */
- servent = getservbyname (port, "tcp");
- if (port == NULL) {
- fprintf (stderr, "Error: Lookup failed for port %s: %s\n",
- port, hstrerror (h_errno));
- return TTT_STATUS_FAILURE;
+ pthread_mutex_init (&server->mutex, NULL);
+
+ server->host = host;
+ server->port = port;
+
+ server->clients = NULL;
+ server->clients_size = 0;
+ server->num_clients = 0;
+}
+
+/* Exported: See ttt-server.h for documentation. */
+ttt_error_t
+ttt_server_register_client (ttt_server_t *server, ttt_client_t *client)
+{
+ int i;
+ ttt_error_t error = TTT_ERROR_NONE;
+ const char *name;
+
+ pthread_mutex_lock (&server->mutex);
+
+ name = ttt_client_get_name (client);
+
+ assert (name != NULL);
+
+ if (name[0] == '\0')
+ return TTT_ERROR_INVALID_NAME;
+
+ for (i = 0; i < server->num_clients; i++) {
+ if (strcmp (ttt_client_get_name (server->clients[i]), name) == 0) {
+ error = TTT_ERROR_INVALID_NAME;
+ goto CLEANUP_LOCK;