static void SocketCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) { // Skip null bytes ssize_t length = CFDataGetLength(data); const char *buffer = (const char *)CFDataGetBytePtr(data); while (length) { while (*buffer == '\0') { buffer++; length--; if (length == 0) return; } size_t extentLength = 0; while ((buffer[extentLength] != '\0') && extentLength != length) { extentLength++; } if (should_print_message(buffer, extentLength)) { printMessage(1, buffer, extentLength); printSeparator(1); } length -= extentLength; buffer += extentLength; } }
static void SocketCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) { // Skip null bytes ssize_t length = CFDataGetLength(data); const char *buffer = (const char *)CFDataGetBytePtr(data); while (length) { while (*buffer == '\0') { buffer++; length--; if (length == 0) goto exit; } size_t extentLength = 0; while ((buffer[extentLength] != '\0') && extentLength != length) { extentLength++; } if (should_print_message(buffer, extentLength)) { printMessage(1, buffer, extentLength); printSeparator(1); } length -= extentLength; buffer += extentLength; } exit: /* * It turns out that every time we get here, we've logged one complete log * statement. (which could be more than one line, but you get the idea.) */ linesLogged++; return; }
void simulator_write_callback(char *p, size_t size){ char buffer[size]; bzero(buffer, sizeof(buffer)); memcpy(&buffer, p, size); if (should_print_message(buffer, size)) { printMessage(1, buffer, size); printSeparator(1); } }