<commit_before>#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/types.h>

#include "lib/sock.h"

static const char * const ssfs_srv_usage[] = {
	"usage: ssfs-srv [options]\n Runs the ssfs server",
  "-h|--help        print this message.",
	"-v|--verbose     increase verbosity about performed actions.",
	"-p|--port        TCP port to listen on. (Default 80)",
};

void usage() {
  printf("%s\n", ssfs_srv_usage[0]);
  for (int i = 1; i < 4; ++i) {
    printf("\t%s\n", ssfs_srv_usage[i]);
  }
}

// TODO: should this close sockets on failure?
int ssfs_serve(char *port, sa_family_t family) {
  int sockfd; // socket we bind
  int connfd; // socket returned by accept
  int status;

  sockfd = ssfs_listen(port, family);
  if (sockfd < 0) {
    return sockfd;
  }

  connfd = ssfs_accept(sockfd);
  if (connfd < 0) {
    return connfd;
  }

  printf("Successfully accepted a connection!\n");
  return 0;
}

int main(int argc, char **argv) {
  int c;
  optind = 0;
  
  int verbosity = 0;<commit_msg>refactor socket library in terms of connection struct<commit_after>#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "lib/sock.h"

static const char * const ssfs_srv_usage[] = {
	"usage: ssfs-srv [options]\n Runs the ssfs server",
  "-h|--help        print this message.",
	"-v|--verbose     increase verbosity about performed actions.",
	"-p|--port        TCP port to listen on. (Default 80)",
};

void usage() {
  printf("%s\n", ssfs_srv_usage[0]);
  for (int i = 1; i < 4; ++i) {
    printf("\t%s\n", ssfs_srv_usage[i]);
  }
}

// TODO: should this close sockets on failure?
int ssfs_serve(char *port, sa_family_t family) {
  int status;
  struct ssfs_conn conn;
  memset(&conn, 0, sizeof(conn));

  status = ssfs_listen(port, family, &conn);
  if (status) {
    return status;
  }

  status = ssfs_accept(&conn);
  if (status) {
    return status;
  }

  printf("Successfully accepted a connection!\n");
  return 0;
}

int main(int argc, char **argv) {
  int c;
  optind = 0;
  
  int verbosity = 0;
{'fraction_non_alphanumeric': 0.15569143932267168, 'fraction_numerical': 0.008936970837253057, 'mean_word_length': 3.2796780684104627, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4383778', 'n_tokens_mistral': 822, 'n_tokens_neox': 789, 'n_words': 228}