Date: Mon, 20 Dec 2004 11:35:47 -0800 From: Julian Elischer <julian@elischer.org> To: aditya eipl <adityaeipl@hotmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: roblem related to sockets in FreeBSD Kernel Message-ID: <41C72993.4070609@elischer.org> In-Reply-To: <BAY20-F53EA27C7F44283FF757B8DFA20@phx.gbl> References: <BAY20-F53EA27C7F44283FF757B8DFA20@phx.gbl>
next in thread | previous in thread | raw e-mail | index | archive | help
look at the netgraph ng_ksocket code.. In fact you may find that you can use it directly. Some people have written their own in-kernel httpd using this and netgraph. aditya eipl wrote: > Hi, > I am writing a socket server in the kernel mode in FreeBSD 4.6.2. This > program accepts connection and receives data on the socket. But we are > not getting the data.In the code: We come to know that the we are > connected we also get the notification for receipt of data but are > unable to fetch the data. Can anybody please let me know what is wrong > in my code? Here are the code snippets: > > After calling soaccept() > I have: > so->so_upcallarg = (caddr_t)upcallargs; > so->so_upcall = socket_incoming; > so->so_rcv.sb_flags |= SB_UPCALL; > so->so_snd.sb_flags |= SB_UPCALL; > > I dont know whether this is required. But as I saw this in the FreeBSD > source I put it. > > I have written socket_incoming as follows: > void socket_incoming(struct socket *so, void *arg, int waitflag) > { > log(LOG_ALERT, "hello: socket_incoming%x \n",so->so_state); > if(so->so_state & SS_ISCONNECTED) > server_receive(so); > return; > } > I have written server receiveas follows: > int server_receive(struct socket *so) > { > struct uio uio; > struct iovec uiovec[2]; > struct mbuf *mp; > int err,i; > int flags, s; > struct socket *head = so; > struct sockaddr *sa = NULL; > char buff[MAX_BYTES_TO_PROCESS]; > log(LOG_ALERT, "hello: connected now try to read data (%x %x) > \n", so, socket_server); > flags = MSG_DONTWAIT ; > > uiovec[0].iov_base = buff; > uiovec[0].iov_len = MAX_BYTES_TO_PROCESS; > uiovec[1].iov_base = NULL; > uiovec[1].iov_len = 0; > > uio.uio_iov = &uiovec[0]; > uio.uio_iovcnt = 1; > uio.uio_offset = -1; > uio.uio_resid = MAX_BYTES_TO_PROCESS; > uio.uio_segflg = UIO_SYSSPACE; > uio.uio_rw = UIO_READ; > uio.uio_procp = p; > err = -1; > { > log(LOG_ALERT, "hello: Calling soreceive\n"); > err = soreceive(so, (so->so_state & SS_ISCONNECTED) ? NULL : > &sa, &uio, &mp, NULL, &flags); > /* err = so->so_proto->pr_usrreqs->pru_soreceive(so, > (so->so_state & SS_ISCONNECTED) ? NULL : &sa, > &uio, NULL, 0, &flags); */ > /* one of the above should work but both of them do not work :( */ > if (err < 0) { > log(LOG_ALERT, "hello: socket receive err \n"); > goto sock_server_exit; > } > log(LOG_ALERT, "hello: socket receive err = %d \n", err); > > } > log(LOG_ALERT, "hello: iolen = %d \n data : > ",uio.uio_iov[0].iov_len); > for(i=0;i< uio.uio_resid;i++) { > log(LOG_ALERT, "%c > ",uio.uio_iov[0].iov_base[MAX_BYTES_TO_PROCESS - i]); > } > /* we see garbage here :( */ > log(LOG_ALERT, "hello: data = %c > \n",uio.uio_iov[0].iov_base[uio.uio_resid-3]); > log(LOG_ALERT, "hello: iovcnt = %d \n",uio.uio_iovcnt); > log(LOG_ALERT, "hello: offset = %d \n",uio.uio_offset); > log(LOG_ALERT, "hello: resid = %d \n",uio.uio_resid); > log(LOG_ALERT, "hello: rw = %d \n",uio.uio_rw); > > log(LOG_ALERT, "hello: msg header iovcnt = %s \n",(char *)mp->m_dat); > sock_server_exit: > return 0; > } > > Any help will be much appreciated. > > _________________________________________________________________ > Searching for your soulmate? Zero in on the perfect choice. > http://www.astroyogi.com/newmsn/astrodate/ Try MSN Astrodate now! > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to > "freebsd-hackers-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41C72993.4070609>