Commits

izdubar committed 9081318

saved 4k of IOP mem in cdvdman/SMB, direct write to buffer

(some small improvment in compat&perfs expected)

Comments (0)

Files changed (6)

modules/iopcore/cdvdman/cdvdman.c

 // !!! ps2ip exports functions pointers !!!
 int (*plwip_close)(int s); 										// #6
 int (*plwip_connect)(int s, struct sockaddr *name, socklen_t namelen); 					// #7
-int (*plwip_recv)(int s, void *mem, int len, unsigned int flags);					// #9
+int (*plwip_recvfrom)(int s, void *header, int hlen, void *payload, int plen, unsigned int flags, struct sockaddr *from, socklen_t *fromlen);	// #10
 int (*plwip_send)(int s, void *dataptr, int size, unsigned int flags); 					// #11
 int (*plwip_socket)(int domain, int type, int protocol); 						// #13
 u32 (*pinet_addr)(const char *cp); 									// #24
 	// Set functions pointers here
 	plwip_close = info.exports[6];
 	plwip_connect = info.exports[7];
-	plwip_recv = info.exports[9];
+	plwip_recvfrom = info.exports[10];
 	plwip_send = info.exports[11];
 	plwip_socket = info.exports[13];
 	pinet_addr = info.exports[24];

modules/iopcore/cdvdman/smb.c

 // !!! ps2ip exports functions pointers !!!
 extern int (*plwip_close)(int s); 						// #6
 extern int (*plwip_connect)(int s, struct sockaddr *name, socklen_t namelen); 	// #7
-extern int (*plwip_recv)(int s, void *mem, int len, unsigned int flags);	// #9
+extern int (*plwip_recvfrom)(int s, void *header, int hlen, void *payload, int plen, unsigned int flags, struct sockaddr *from, socklen_t *fromlen);	// #10
 extern int (*plwip_send)(int s, void *dataptr, int size, unsigned int flags); 	// #11
 extern int (*plwip_socket)(int domain, int type, int protocol); 		// #13
 extern u32 (*pinet_addr)(const char *cp); 					// #24
 static u16 UID, TID;
 static int main_socket;
 
-static u8 SMB_buf[MAX_SMB_BUF+1024] __attribute__((aligned(64)));
+static u8 SMB_buf[1024] __attribute__((aligned(64)));
 
 //-------------------------------------------------------------------------
 int rawTCP_SetSessionHeader(u32 size) // Write Session Service header: careful it's raw TCP transport here and not NBT transport
 		return -1;
 
 receive:
-	rcv_size = plwip_recv(main_socket, SMB_buf, sizeof(SMB_buf), 0);
+	rcv_size = plwip_recvfrom(main_socket, NULL, 0, SMB_buf, sizeof(SMB_buf), 0, NULL, NULL);
 	if (rcv_size <= 0)
 		return -2;
 
 	totalpkt_size = rawTCP_GetSessionHeader() + 4;
 
 	while (rcv_size < totalpkt_size) {
-		pkt_size = plwip_recv(main_socket, &SMB_buf[rcv_size], sizeof(SMB_buf) - rcv_size, 0);
+		pkt_size = plwip_recvfrom(main_socket, NULL, 0, &SMB_buf[rcv_size], sizeof(SMB_buf) - rcv_size, 0, NULL, NULL);
 		if (pkt_size <= 0)
 			return -2;
 		rcv_size += pkt_size;
 	register int rcv_size, pkt_size;
 
 	struct ReadAndXRequest_t *RR = (struct ReadAndXRequest_t *)SMB_buf;
-	struct ReadAndXResponse_t *RRsp = (struct ReadAndXResponse_t *)SMB_buf;
 
 	WAITIOSEMA(io_sema);
 
 
 	plwip_send(main_socket, SMB_buf, 63, 0);
 receive:
-	rcv_size = plwip_recv(main_socket, SMB_buf, sizeof(SMB_buf), 0);
+	rcv_size = plwip_recvfrom(main_socket, SMB_buf, 63, readbuf, nbytes, 0, NULL, NULL);
 
 	if (SMB_buf[0] != 0)	// dropping NBSS Session Keep alive
 		goto receive;
 
 	// Handle fragmented packets
 	while (rcv_size < (rawTCP_GetSessionHeader() + 4)) {
-		pkt_size = plwip_recv(main_socket, &SMB_buf[rcv_size], sizeof(SMB_buf), 0); // - rcv_size
+		pkt_size = plwip_recvfrom(main_socket, NULL, 0, &((u8 *)readbuf)[rcv_size - 63], nbytes, 0, NULL, NULL); // - rcv_size
 		rcv_size += pkt_size;
 	}
 
-	mips_memcpy(readbuf, &SMB_buf[4 + RRsp->DataOffset], nbytes);
-
 	SIGNALIOSEMA(io_sema);
 
 	return 1;

modules/iopcore/cdvdman/smb.h

 int smb_ReadCD(unsigned int lsn, unsigned int nsectors, void *buf, int part_num);
 int smb_Disconnect(void);
 
-#define MAX_SMB_BUF 		4096 // must fit on u16 !!!
 #define MAX_SMB_SECTORS 	2
 
 #endif

modules/network/SMSTCPIP/include/lwip/sockets.h

 int lwip_listen(int s, int backlog);
 int lwip_recv(int s, void *mem, int len, unsigned int flags);
 int lwip_read(int s, void *mem, int len);
-int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
+int lwip_recvfrom(int s, void *header, int hlen, void *payload, int plen, unsigned int flags,
       struct sockaddr *from, socklen_t *fromlen);
 int lwip_send(int s, void *dataptr, int size, unsigned int flags);
 int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,

modules/network/SMSTCPIP/sockets.c

 }
 
 int
-lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
+lwip_recvfrom(int s, void *header, int hlen, void *payload, int plen, unsigned int flags,
         struct sockaddr *from, socklen_t *fromlen)
 {
   struct lwip_socket *sock;
   struct netbuf *buf;
-  u16_t buflen, copylen;
+  u16_t avail_len;
   struct ip_addr *addr;
   u16_t port;
 
 
-  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags));
+  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, payload, plen, flags));
   sock = get_socket(s);
   if (!sock) {
     set_errno(EBADF);
     }
   }
 
-  buflen = netbuf_len(buf);
+  avail_len = netbuf_len(buf);
 
-  buflen -= sock->lastoffset;
-
-  if (len > buflen) {
-    copylen = buflen;
-  } else {
-    copylen = len;
-  }
+  avail_len -= sock->lastoffset;
 
   /* copy the contents of the received buffer into
      the supplied memory pointer mem */
-  netbuf_copy_partial(buf, mem, copylen, sock->lastoffset);
+  if (hlen) {
+    if (hlen > avail_len)
+      hlen = avail_len;
+
+    netbuf_copy_partial(buf, header, hlen, sock->lastoffset);
+    avail_len -= hlen;
+  }
+
+  if (plen > avail_len)
+    plen = avail_len;
+
+  netbuf_copy_partial(buf, payload, plen, sock->lastoffset + hlen);
+  avail_len -= plen;
 
   /* Check to see from where the data was. */
   if (from && fromlen) {
     ip_addr_debug_print(SOCKETS_DEBUG, addr);
     LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
 #endif
-
   }
 
   /* If this is a TCP socket, check if there is data left in the
      buffer. If so, it should be saved in the sock structure for next
      time around. */
-  if (netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) {
+  if (netconn_type(sock->conn) == NETCONN_TCP && avail_len > 0) {
     sock->lastdata = buf;
-    sock->lastoffset += copylen;
+    sock->lastoffset += hlen + plen;
   } else {
     sock->lastdata = NULL;
     sock->lastoffset = 0;
     netbuf_delete(buf);
   }
 
-
   sock_set_errno(sock, 0);
-  return copylen;
+  return hlen + plen;
 }
 
 int
 lwip_read(int s, void *mem, int len)
 {
-  return lwip_recvfrom(s, mem, len, 0, NULL, NULL);
+  return lwip_recvfrom(s, NULL, 0, mem, len, 0, NULL, NULL);
 }
 
 int
 lwip_recv(int s, void *mem, int len, unsigned int flags)
 {
-  return lwip_recvfrom(s, mem, len, flags, NULL, NULL);
+  return lwip_recvfrom(s, NULL, 0, mem, len, flags, NULL, NULL);
 }
 
 int

src/supportbase.c

 	}
 
 	memcpy((void*)((u32)cdvdman_irx + i), isoname, strlen(isoname) + 1);
-	memcpy((void*)((u32)cdvdman_irx + i + 33), &game->parts, 1); // TODO long filename
+	memcpy((void*)((u32)cdvdman_irx + i + 33), &game->parts, 1);
 	memcpy((void*)((u32)cdvdman_irx + i + 34), &game->media, 1);
 	if (compatmask & COMPAT_MODE_2) {
 		u32 alt_read_mode = 1;