su_port.c 2.65 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@ingroup su_wait
 * @CFILE su_port.c
 *
 * OS-Independent Socket Syncronization Interface.
 *
30 31 32
 * This looks like nth reincarnation of "reactor". It implements the
 * poll/select/WaitForMultipleObjects and message passing functionality. 
 * This is virtual implementation:
Pekka Pessi's avatar
Pekka Pessi committed
33 34 35 36 37 38 39 40 41 42
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * @author Kai Vehmanen <kai.vehmanen@nokia.com>
 *
 * @date Created: Tue Sep 14 15:51:04 1999 ppessi
 */

#include "config.h"

#include "su_port.h"
43

44 45
#include <string.h>
#include <stdlib.h>
Pekka Pessi's avatar
Pekka Pessi committed
46

47
static su_port_t *(*preferred_su_port_create)(void);
Pekka Pessi's avatar
Pekka Pessi committed
48

49 50 51 52
/** Explicitly set the preferred su_port_t implementation.
 *
 * @sa su_epoll_port_create(), su_poll_port_create(), su_select_port_create()
 */
53
void su_port_prefer(su_port_t *(*implementation)(void))
Pekka Pessi's avatar
Pekka Pessi committed
54
{
55
  preferred_su_port_create = implementation;
Pekka Pessi's avatar
Pekka Pessi committed
56 57
}

58
/** Create the preferred su_port_t implementation.
Pekka Pessi's avatar
Pekka Pessi committed
59
 */
60
su_port_t *su_port_create(void)
Pekka Pessi's avatar
Pekka Pessi committed
61
{
62
  if (preferred_su_port_create == NULL) {
63
    char const *SU_PORT = getenv("SU_PORT");
64
    su_port_t *(*create)(void) = NULL;
Pekka Pessi's avatar
Pekka Pessi committed
65

66 67 68
    if (SU_PORT == NULL)
      ;
#if HAVE_POLL_PORT
69
#if HAVE_EPOLL
70
    else if (strcmp(SU_PORT, "epoll") == 0)
71
      create = su_epoll_port_create;
72
#endif
73
    else if (strcmp(SU_PORT, "poll") == 0)
74
      create = su_poll_port_create;
75 76
#else
#error no poll!
77
#endif
78
#if HAVE_SELECT
79
    else if (strcmp(SU_PORT, "select") == 0)
80
      create = su_select_port_create;
81
#endif
82 83 84

    if (create == NULL) {
      create = su_epoll_port_create;
85
#if HAVE_POLL_PORT
86
#if HAVE_EPOLL
87 88 89
      create = su_epoll_port_create;
#else
      create = su_poll_port_create;
90
#endif
91
#else
92 93
#if HAVE_SELECT
      create = su_select_port_create;
94
#endif
Pekka Pessi's avatar
Pekka Pessi committed
95
#endif
96
    }
97 98 99

    if (create)
      preferred_su_port_create = create;
Pekka Pessi's avatar
Pekka Pessi committed
100 101
  }

102 103
  if (preferred_su_port_create)
    return preferred_su_port_create();
Pekka Pessi's avatar
Pekka Pessi committed
104

105
  return NULL;
Pekka Pessi's avatar
Pekka Pessi committed
106
}