From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 20 19:35:51 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E868416A4D0 for ; Mon, 20 Dec 2004 19:35:50 +0000 (GMT) Received: from mail.vicor-nb.com (bigwoop.vicor-nb.com [208.206.78.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id F087043D60 for ; Mon, 20 Dec 2004 19:35:47 +0000 (GMT) (envelope-from julian@elischer.org) Received: from elischer.org (julian.vicor-nb.com [208.206.78.97]) by mail.vicor-nb.com (Postfix) with ESMTP id A73257A403; Mon, 20 Dec 2004 11:35:47 -0800 (PST) Message-ID: <41C72993.4070609@elischer.org> Date: Mon, 20 Dec 2004 11:35:47 -0800 From: Julian Elischer User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3.1) Gecko/20030516 X-Accept-Language: en, hu MIME-Version: 1.0 To: aditya eipl References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: roblem related to sockets in FreeBSD Kernel X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Dec 2004 19:35:51 -0000 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"