_PUBLIC_ ssize_t swrap_send(int s, const void *buf, size_t len, int flags) { int ret; struct socket_info *si = find_socket_info(s); if (!si) { return real_send(s, buf, len, flags); } ret = real_send(s, buf, len, flags); if (ret == -1) { swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len); swrap_dump_packet(si, NULL, SWRAP_SEND_RST, NULL, 0); } else { swrap_dump_packet(si, NULL, SWRAP_SEND, buf, ret); } return ret; }
ssize_t send(int s, const void *buf, size_t len, int flags) { init(); if (!forked || (s != ssl_socket)) { return real_send(s,buf,len,flags); } // XXX what about flags return SSL_write(ssl_ssl,buf,len); }
ssize_t send(int s, const void *buf, size_t len, int flags) { ssize_t retval; print_trace ("%*ssend(%d, %p, %d, %d)=...\n", indent, "", s, buf, len, flags); indent+=2; /* call the real send function */ retval = real_send (s, buf, len, flags); indent-=2; print_trace ("%*ssend(%d, %p, %d, %d)=%d\n", indent, "", s, buf, len, flags, retval); return retval; }
/*---------------------------------------------------------------------------*/ static void advanceSlot(struct rtimer *t, void *ptr, int status) { off(TURN_OFF); last = RTIMER_TIME(t); if(!(rtimer_set(t, last + REGULAR_SLOT, 1, (void (*)(struct rtimer *, void *))advanceSlot, NULL) == RTIMER_OK)) { printf("%s\n", "WPI-MAC: Could not schedule task!!!!!"); } if(current_slot == TOTAL_SLOTS + 1) { current_slot = BROADCAST_SLOT; } else { current_slot++; } if(current_slot > (TOTAL_SLOTS - 1)) { current_slot = BROADCAST_SLOT; } //printf("Slot is now %u\n", current_slot); unsigned char somethingToSend = check_buffers(current_slot); if(somethingToSend) { // grab the necessary info from our queue QueuedPacket *curr = QPQueue[current_slot]; real_send(curr->sent, curr->ptr, curr->packet); } else if(current_slot == BROADCAST_SLOT || current_slot == node_id) { // just need to be awake to listen // if(!(rtimer_set(t, last + CONTENTION_PREPARE + (CONTENTION_TICKS * (CONTENTION_SLOTS)), 1, (void (*)(struct rtimer *, void *))async_on, NULL) == RTIMER_OK)){ // printf("%s\n", "Could not schedule task!!!!!"); // } rtimer_clock_t stall = last + CONTENTION_PREPARE + (CONTENTION_TICKS * (CONTENTION_SLOTS)); // printf("STALLLLL: %u %u %u %u\n", RTIMER_NOW(), stall, REGULAR_SLOT, last); while(RTIMER_CLOCK_LT(RTIMER_NOW(), stall)); if(!radio_is_on) on(); } else { // we can snooze if(radio_is_on) off(TURN_OFF); } }
_PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { struct sockaddr_un un_addr; int ret; struct socket_info *si = find_socket_info(s); int bcast = 0; if (!si) { return real_sendto(s, buf, len, flags, to, tolen); } if (si->connected) { if (to) { errno = EISCONN; return -1; } to = si->peername; tolen = si->peername_len; } len = MIN(len, 1500); switch (si->type) { case SOCK_STREAM: ret = real_send(s, buf, len, flags); break; case SOCK_DGRAM: if (si->bound == 0) { ret = swrap_auto_bind(si, si->family); if (ret == -1) return -1; } ret = sockaddr_convert_to_un(si, to, tolen, &un_addr, 0, &bcast); if (ret == -1) return -1; if (bcast) { struct stat st; unsigned int iface; unsigned int prt = ntohs(((const struct sockaddr_in *)to)->sin_port); char type; type = SOCKET_TYPE_CHAR_UDP; for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s/"SOCKET_FORMAT, socket_wrapper_dir(), type, iface, prt); if (stat(un_addr.sun_path, &st) != 0) continue; /* ignore the any errors in broadcast sends */ real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); } swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); return len; } ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr)); break; default: ret = -1; errno = EHOSTUNREACH; break; } /* to give better errors */ if (ret == -1 && errno == ENOENT) { errno = EHOSTUNREACH; } if (ret == -1) { swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); swrap_dump_packet(si, to, SWRAP_SENDTO_UNREACH, buf, len); } else { swrap_dump_packet(si, to, SWRAP_SENDTO, buf, ret); } return ret; }