removed old debug code
This commit is contained in:
@@ -102,54 +102,4 @@ extern "C" {
|
|||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // _SDK_DEBUG_H_
|
#endif // _SDK_DEBUG_H_
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void dwr(int level, const char *fmt, ... )
|
|
||||||
{
|
|
||||||
#if defined(SDK_DEBUG)
|
|
||||||
if(level > DEBUG_LEVEL)
|
|
||||||
return;
|
|
||||||
int saveerr;
|
|
||||||
saveerr = errno;
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
char timestring[20];
|
|
||||||
time_t timestamp;
|
|
||||||
timestamp = time(NULL);
|
|
||||||
strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(×tamp));
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
pid_t tid = gettid();
|
|
||||||
#elif defined(__linux__)
|
|
||||||
pid_t tid = 5;//syscall(SYS_gettid);
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
pid_t tid = pthread_mach_thread_np(pthread_self());
|
|
||||||
#endif
|
|
||||||
#if defined(SDK_DEBUG_LOG_TO_FILE)
|
|
||||||
if(!debug_logfile) { // Try to get logfile from env
|
|
||||||
debug_logfile = getenv("ZT_SDK_LOGFILE");
|
|
||||||
}
|
|
||||||
if(debug_logfile) {
|
|
||||||
FILE *file = fopen(debug_logfile,"a");
|
|
||||||
fprintf(file, "%s [tid=%7d] ", timestring, tid);
|
|
||||||
vfprintf(file, fmt, ap);
|
|
||||||
fclose(file);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
va_start(ap, fmt);
|
|
||||||
fprintf(stderr, "%s [tid=%7d] ", timestring, tid);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
|
|
||||||
// Outputs to Android debug console
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
__android_log_vprint(ANDROID_LOG_VERBOSE, "ZT-JNI", fmt, ap);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fflush(stderr);
|
|
||||||
errno = saveerr;
|
|
||||||
va_end(ap);
|
|
||||||
#endif // _SDK_DEBUG
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -93,11 +93,18 @@ class ZTSDK : NSObject
|
|||||||
zt_leave_network(nwid);
|
zt_leave_network(nwid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the address of this device on a given ZeroTier network
|
// Returns the IPV4 address of this device on a given ZeroTier network
|
||||||
func get_address(nwid: String) -> (String, String)
|
func get_ipv4_address(nwid: String) -> String? {
|
||||||
{
|
var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||||
// zts_get_addresses(nwid, addrstr);
|
zt_get_ipv4_address(nwid,&str_buf);
|
||||||
return ("ipv4", "ipv6")
|
return String(str_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the IPV6 address of this device on a given ZeroTier network
|
||||||
|
func get_ipv6_address(nwid: String) -> String? {
|
||||||
|
var str_buf = [Int8](count: 16, repeatedValue: 0)
|
||||||
|
zt_get_ipv6_address(nwid,&str_buf);
|
||||||
|
return String(str_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,11 +141,25 @@ class ZTSDK : NSObject
|
|||||||
return zt_socket(socket_family, socket_type, socket_protocol);
|
return zt_socket(socket_family, socket_type, socket_protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(fd: Int32, _ addr: ZTAddress) -> Int32 {
|
func connect(fd: Int32, _ addr: ZTAddress, _ nwid: String? = nil) -> Int32 {
|
||||||
return zt_connect(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
if(nwid == nil) { // no nwid is provided to check for address, try once and fail
|
||||||
|
return zt_connect(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||||
|
}
|
||||||
|
while(true) { // politely wait until an address is provided. simulates a blocking call
|
||||||
|
if(self.get_ipv4_address(nwid!) != nil) {
|
||||||
|
return zt_connect(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
func bind(fd: Int32, _ addr: ZTAddress) -> Int32 {
|
func bind(fd: Int32, _ addr: ZTAddress, _ nwid: String? = nil) -> Int32 {
|
||||||
return zt_bind(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
if(nwid == nil) { // no nwid is provided to check for address, try once and fail
|
||||||
|
return zt_bind(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||||
|
}
|
||||||
|
while(true) { // politely wait until an address is provided. simulates a blocking call
|
||||||
|
if(self.get_ipv4_address(nwid!) != nil) {
|
||||||
|
return zt_bind(Int32(fd), addr.to_sockaddr_in(), UInt32(addr.len()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func accept(fd: Int32, _ addr: ZTAddress) -> Int32 {
|
func accept(fd: Int32, _ addr: ZTAddress) -> Int32 {
|
||||||
|
|||||||
Reference in New Issue
Block a user