3 /* xbt_peer_t management functions */
5 /* Copyright (c) 2006 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(peer, xbt, "peer management");
16 /** \brief constructor */
17 xbt_peer_t xbt_peer_new(const char *name, int port)
19 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
20 res->name = xbt_strdup(name);
25 xbt_peer_t xbt_peer_copy(xbt_peer_t h)
27 return xbt_peer_new(h->name, h->port);
30 /** \brief constructor. Argument should be of form '(peername):(port)'. */
31 xbt_peer_t xbt_peer_from_string(const char *peerport)
33 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
34 char *name = xbt_strdup(peerport);
35 char *port_str = strchr(name, ':');
37 "argument of xbt_peer_from_string should be of form <peername>:<port>, it's '%s'",
42 res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
43 res->port = atoi(port_str);
48 /** \brief destructor */
49 void xbt_peer_free(xbt_peer_t peer)
58 /** \brief Freeing function for dynars of xbt_peer_t */
59 void xbt_peer_free_voidp(void *d)
61 xbt_peer_free((xbt_peer_t) * (void **) d);