obex_transport.c

来自「sparc硬件平台上的红外协议」· C语言 代码 · 共 142 行

C
142
字号
/**********************************************************************                * Filename:      obex_transport.c* Version:       * Description:   Code to handle different types of transports* Status:        Experimental.* Author:        Dag Brattli <dagb@cs.uit.no>* Created at:    Sat May  1 20:15:04 1999* CVS ID:        $Id: obex_transport.c,v 1.29 2006/05/04 11:24:21 holtmann Exp $* *     Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved.*     Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved.*     *     This library is free software; you can redistribute it and/or*     modify it under the terms of the GNU Lesser General Public*     License as published by the Free Software Foundation; either*     version 2 of the License, or (at your option) any later version.**     This library is distributed in the hope that it will be useful,*     but WITHOUT ANY WARRANTY; without even the implied warranty of*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU*     Lesser General Public License for more details.**     You should have received a copy of the GNU Lesser General Public*     License along with this library; if not, write to the Free Software*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, *     MA  02111-1307  USA*     ********************************************************************/#include <string.h>#include <stdio.h>#include "obex_main.h"#include "irobex.h"#include "obex_transport.h"/** Function obex_transport_handle_input(self, timeout)**    Used when working in synchronous mode.**/int obex_transport_handle_input(obex_t *self, int timeout){	int ret;		DEBUG(3, "\n");	obex_return_val_if_fail(self != NULL, -1);		ret = obex_data_indication(self, NULL, 0);		return ret;}/** Function obex_transport_disconnect_request (self)**    Disconnect transport**/void obex_transport_disconnect_request(obex_t *self){	//	irobex_disconnect_request(self);		self->trans.connected = FALSE;}/** Function obex_transport_listen (self)**    Prepare for incomming connections**/int obex_transport_listen(obex_t *self){	int ret = -1;	ret = irobex_listen(self);	return ret;	}/** does fragmented write*/static int do_write( buf_t *msg, int mtu){	int actual = -1;	int size;		/* Send and fragment if necessary  */	while (msg->data_size) {		if (msg->data_size > mtu)			size = mtu;		else			size = msg->data_size;		DEBUG(5, "sending %d bytes\n", size);				actual = irda_sendmsg(msg->data,size);		if (actual <= 0)			return actual;		/* Hide sent data */		buf_remove_begin(msg, actual);	}	return actual;}/** Function obex_transport_write ()**    Do the writing**/int obex_transport_write(obex_t *self, buf_t *msg){	int actual = -1;		DEBUG(4, "\n");	actual = do_write( msg, self->trans.mtu);		return actual;}/** Function obex_transport_read ()**    Do the reading**/int obex_transport_read(obex_t *self, int max, uint8_t *buf, int buflen){	int actual = -1;	buf_t *msg = self->rx_msg;		DEBUG(5, "Request to read max %d bytes\n", max);    actual = irda_recvmsg_stream(buf_reserve_end(msg, max),max);		buf_remove_end(msg, max - actual);		return actual;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?