Changeset 5368:1c35d975f8fe in roaraudio
- Timestamp:
- 12/20/11 22:17:27 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/basic.h
r5365 r5368 84 84 85 85 86 int roar_connect_raw (const char * server, int flags, uint_least32_t timeout);87 88 86 int roar_connect (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout); 89 87 int roar_connect_none (struct roar_connection * con); -
include/roaraudio.h
r5339 r5368 199 199 // aliases: 200 200 #define ROAR_DEFAULT_HOST ROAR_DEFAULT_INET4_HOST 201 #define ROAR_DEFAULT_HOSTPORT ROAR_DEFAULT_HOST ":16002" 201 202 202 203 // IPv6: -
libroar/basic.c
r5365 r5368 36 36 #include "libroar.h" 37 37 38 int roar_connect_raw (const char * server, int flags, uint_least32_t timeout) { 38 static int _connect_server(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) { 39 #if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT) 40 struct stat sockstat; 41 #endif 42 const char * obj = NULL; 43 char user_sock[128]; 44 int is_decnet = 0; 45 int port = 0; 46 int i = 0; 47 int fh = -1; 48 int err; 49 50 if ( con == NULL || server == NULL ) { 51 roar_err_set(ROAR_ERROR_FAULT); 52 return -1; 53 } 54 55 if ( !strcmp(server, "+invalid") ) { 56 roar_err_set(ROAR_ERROR_CANCELED); 57 return -1; 58 } else if ( !strncmp(server, "+dstr=", 6) ) { 59 if ( roar_vio_open_dstr_simple(con->viocon, server+6, ROAR_VIOF_READWRITE) == -1 ) 60 return -1; 61 con->flags |= ROAR_CON_FLAGS_VIO; 62 return 0; 63 } 64 65 strncpy(user_sock, server, sizeof(user_sock)-1); 66 user_sock[sizeof(user_sock)-1] = 0; 67 68 69 if ( *user_sock != '/' ) { // don't test AF_UNIX sockets for ports 70 for (i = 0; user_sock[i] != 0; i++) { 71 if ( user_sock[i] == ':' ) { 72 if ( user_sock[i+1] == ':' ) { // DECnet, leave unchanged 73 is_decnet = 1; 74 obj = &user_sock[i+2]; 75 break; 76 } 77 78 port = atoi(&(user_sock[i+1])); 79 user_sock[i] = 0; 80 break; 81 } 82 } 83 } 84 85 if ( is_decnet ) { 86 if ( *user_sock == ':' ) { 87 if ( roar_socket_get_local_nodename() != NULL ) { 88 strncpy(user_sock, roar_socket_get_local_nodename(), sizeof(user_sock)-1); 89 user_sock[sizeof(user_sock)-1] = 0; 90 roar_mm_strlcat(user_sock, server, sizeof(user_sock)-1); 91 user_sock[sizeof(user_sock)-1] = 0; 92 obj = strstr(user_sock, "::"); 93 obj += 2; 94 } 95 } 96 97 if ( *obj == 0 ) { 98 #ifdef DN_MAXOBJL 99 roar_mm_strlcat(user_sock, ROAR_DEFAULT_OBJECT, sizeof(user_sock)-1); 100 user_sock[sizeof(user_sock)-1] = 0; 101 #else 102 ROAR_ERR("roar_connect_raw(*): size of DECnet object unknown."); 103 #endif 104 } 105 ROAR_DBG("roar_connect_raw(*): user_sock='%s'", user_sock); 106 } 107 108 if ( port || is_decnet ) { 109 fh = roar_socket_connect(user_sock, port); 110 // restore the original string 111 user_sock[i] = ':'; 112 } else { 113 #if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT) 114 if ( user_sock[0] == '/' ) { 115 if ( stat(user_sock, &sockstat) == 0 ) { 116 if ( S_ISCHR(sockstat.st_mode) ) { 117 return open(user_sock, O_RDWR|O_NOCTTY, 0666); 118 } 119 } 120 } 121 #endif 122 fh = roar_socket_connect(user_sock, ROAR_DEFAULT_PORT); 123 } 124 125 if ( fh == -1 ) 126 return -1; 127 128 if ( roar_vio_open_fh_socket(con->viocon, fh) == -1 ) { 129 err = roar_error; 130 #ifdef ROAR_TARGET_WIN32 131 closesocket(fh); 132 #else 133 close(fh); 134 #endif 135 roar_error = err; 136 return -1; 137 } else { 138 con->flags |= ROAR_CON_FLAGS_VIO; 139 } 140 141 roar_err_set(ROAR_ERROR_NONE); 142 return 0; 143 } 144 145 static int roar_connect_raw (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) { 39 146 #ifdef ROAR_HAVE_LIBSLP 40 147 struct roar_libroar_config * config = roar_libroar_get_config(); … … 43 150 char * roar_server; 44 151 int i = 0; 45 int port = 0;46 int fh = -1;47 int is_decnet = 0;48 const char * obj = NULL;49 152 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 50 153 struct passwd * pwd; … … 60 163 int workarounds_store; 61 164 #endif 62 #if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT)63 struct stat sockstat;64 #endif65 165 66 166 roar_err_set(ROAR_ERROR_UNKNOWN); … … 75 175 76 176 77 if ( server == NULL )177 if ( server == NULL || *server == 0 ) 78 178 server = roar_libroar_get_server(); 79 179 80 if ( server == NULL && (roar_server = getenv("ROAR_SERVER")) != NULL)81 server = roar_server;180 if ( server == NULL || *server == 0 ) 181 server = getenv("ROAR_SERVER"); 82 182 83 183 #ifdef ROAR_HAVE_LIBX11 84 if ( server == NULL ) {184 if ( server == NULL || *server == 0 ) { 85 185 if ( (x11con = roar_x11_connect(NULL)) != NULL ) { 86 186 server = roar_x11_get_prop(x11con, "ROAR_SERVER"); … … 91 191 92 192 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 93 if ( server == NULL&& (i = readlink("/etc/roarserver", user_sock, sizeof(user_sock)-1)) != -1 ) {193 if ( (server == NULL || *server == 0) && (i = readlink("/etc/roarserver", user_sock, sizeof(user_sock)-1)) != -1 ) { 94 194 user_sock[i] = 0; 95 195 server = user_sock; … … 129 229 user_sock[sizeof(user_sock)-1] = 0; 130 230 131 if ( (fh = roar_socket_connect(user_sock, 0)) != -1)132 return fh;133 134 if ( (fh = roar_socket_connect(ROAR_DEFAULT_SOCK_GLOBAL, 0)) != -1)135 return fh;136 #endif 137 138 if ( (fh = roar_socket_connect(ROAR_DEFAULT_HOST, ROAR_DEFAULT_PORT)) != -1)139 return fh;231 if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 ) 232 return 0; 233 234 if ( _connect_server(con, ROAR_DEFAULT_SOCK_GLOBAL, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 ) 235 return 0; 236 #endif 237 238 if ( _connect_server(con, ROAR_DEFAULT_HOSTPORT, ROAR_SOCKET_TYPE_TCP, flags, timeout) == 0 ) 239 return 0; 140 240 141 241 #ifdef ROAR_HAVE_LIBDNET … … 143 243 if ( roar_socket_get_local_nodename() ) { 144 244 snprintf(user_sock, 79, "%s::%s", roar_socket_get_local_nodename(), ROAR_DEFAULT_OBJECT); 145 if ( (fh = roar_socket_connect(user_sock, ROAR_DEFAULT_NUM)) != -1)146 return fh;245 if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_DECNET, flags, timeout) == 0 ) 246 return 0; 147 247 } 148 248 } 149 249 #endif 150 250 151 if ( (fh = roar_socket_connect("+abstract", 0)) != -1)152 return fh;251 if ( _connect_server(con, "+abstract", -1, flags, timeout) == 0 ) 252 return 0; 153 253 154 254 #ifdef ROAR_HAVE_LIBSLP … … 157 257 ) { 158 258 if ( (server = roar_slp_find_roard(0)) != NULL ) { 159 if ( (fh = roar_connect_raw(server, 0, 0)) != -1)160 return fh;259 if ( _connect_server(con, server, -1, 0, 0) == 0 ) 260 return 0; 161 261 162 262 /* in case we can not connect to the server given this may be a cache problem, … … 164 264 ROAR_WARN("roar_connect_raw(*): Can not connect to SLP located server, disabling cache"); 165 265 if ( (server = roar_slp_find_roard(1)) != NULL ) 166 if ( (fh = roar_connect_raw(server, 0, 0)) != -1)167 return fh;266 if ( _connect_server(con, server, -1, 0, 0) == 0 ) 267 return 0; 168 268 } 169 269 } … … 175 275 if ( list != NULL ) { 176 276 for (i = 0; list[i].server != NULL; i++) { 177 if ( (fh = roar_connect_raw(list[i].server, 0, 0)) != -1) {277 if ( _connect_server(con, list[i].server, -1, 0, 0) == 0 ) { 178 278 roar_enum_servers_free(list); 179 return fh;279 return 0; 180 280 } 181 281 } … … 188 288 } else { 189 289 /* connect via (char*)server */ 190 // find a port: 191 192 if ( !strcmp(server, "+invalid") ) { 193 roar_err_set(ROAR_ERROR_CANCELED); 194 return -1; 195 } 196 197 strncpy(user_sock, server, sizeof(user_sock)-1); 198 user_sock[sizeof(user_sock)-1] = 0; 199 200 if ( *user_sock != '/' ) { // don't test AF_UNIX sockets for ports 201 for (i = 0; user_sock[i] != 0; i++) { 202 if ( user_sock[i] == ':' ) { 203 if ( user_sock[i+1] == ':' ) { // DECnet, leave unchanged 204 is_decnet = 1; 205 obj = &user_sock[i+2]; 206 break; 207 } 208 209 port = atoi(&(user_sock[i+1])); 210 user_sock[i] = 0; 211 break; 212 } 213 } 214 } 215 216 if ( is_decnet ) { 217 if ( *user_sock == ':' ) { 218 if ( roar_socket_get_local_nodename() != NULL ) { 219 strncpy(user_sock, roar_socket_get_local_nodename(), sizeof(user_sock)-1); 220 user_sock[sizeof(user_sock)-1] = 0; 221 roar_mm_strlcat(user_sock, server, sizeof(user_sock)-1); 222 user_sock[sizeof(user_sock)-1] = 0; 223 obj = strstr(user_sock, "::"); 224 obj += 2; 225 } 226 } 227 228 if ( *obj == 0 ) { 229 #ifdef DN_MAXOBJL 230 roar_mm_strlcat(user_sock, ROAR_DEFAULT_OBJECT, sizeof(user_sock)-1); 231 user_sock[sizeof(user_sock)-1] = 0; 232 #else 233 ROAR_ERR("roar_connect_raw(*): size of DECnet object unknown."); 234 #endif 235 } 236 ROAR_DBG("roar_connect_raw(*): user_sock='%s'", user_sock); 237 } 238 239 if ( port || is_decnet ) { 240 fh = roar_socket_connect(user_sock, port); 241 // restore the original string 242 user_sock[i] = ':'; 243 } else { 244 #if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT) 245 if ( user_sock[0] == '/' ) { 246 if ( stat(user_sock, &sockstat) == 0 ) { 247 if ( S_ISCHR(sockstat.st_mode) ) { 248 return open(user_sock, O_RDWR|O_NOCTTY, 0666); 249 } 250 } 251 } 252 #endif 253 fh = roar_socket_connect(user_sock, ROAR_DEFAULT_PORT); 254 } 255 } 256 257 ROAR_DBG("roar_connect_raw(*) = %i", fh); 258 259 return fh; 290 if ( _connect_server(con, server, -1, flags, timeout) == 0 ) 291 return 0; 292 } 293 294 roar_err_set(ROAR_ERROR_NODEV); 295 ROAR_DBG("roar_connect_raw(*) = -1 // error=NODEV"); 296 return -1; 260 297 } 261 298 262 299 int roar_connect (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) { 263 int fh;264 int err;265 266 300 if ( con == NULL ) { 267 301 roar_err_set(ROAR_ERROR_FAULT); … … 269 303 } 270 304 305 if ( roar_connect_none(con) == -1 ) 306 return -1; 307 271 308 roar_err_set(ROAR_ERROR_UNKNOWN); 272 fh = roar_connect_raw(server, flags, timeout); 273 274 if ( fh == -1 ) 275 return -1; 276 277 if ( roar_connect_fh(con, fh) == -1 ) { 278 err = roar_error; 279 #ifdef ROAR_TARGET_WIN32 280 closesocket(fh); 281 #else 282 close(fh); 283 #endif 284 roar_error = err; 285 return -1; 286 } 309 if ( roar_connect_raw(con, server, flags, timeout) == -1 ) 310 return -1; 287 311 288 312 if ( server != NULL ) {
Note: See TracChangeset
for help on using the changeset viewer.