如何在C ++中确保正确比较Write Buffer和Read Buffer [英] How to ensure proper Compare for Write Buffer and Read Buffer in C++

查看:255
本文介绍了如何在C ++中确保正确比较Write Buffer和Read Buffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的C ++应用程序中,我试图分配Buffer并读取分配的缓冲区,并确保Read SCSI()成功返回(良好状态)

我的脚步. 1.写入某些缓冲区检查写入缓冲区成功假定512个字节
2.读取写入的同一缓冲区,以确保ReadSCSI成功.
3.最终确保写入缓冲区和读取缓冲区的比较相同,

我需要一小段代码(直接比较Write Buffer/Read Buffer而不进行卷积),其中 Compare (Read/Write)缓冲区是相同的,如果没有,则抛出异常?

我正在使用VS2008 IDE,VC ++环境.(Windows 7 o/s).

问候,
Vishalk_90





Hi,

In my C++ application, wherein, I am trying to allocate Buffer and Read the buffer allocated, and ensure Read SCSI() returns successfully(Good Status)

my Steps. 1. Write Some buffer check write buffer successfull assume 512 bytes
2. Read the same buffer written ensure ReadSCSI is successfull.
3. Ultimately ensure Write buffer and Read buffer comparison is identical,

I need a snippet of code(directly compares Write Buffer/Read Buffer without convolutions) where in Compare(Read/Write)buffer is same, if not otherwise throw an exception?

I am using VS2008 IDE, VC++ environment.(Windows 7 o/s).

With Regards,
Vishalk_90





<pre lang="c++">SaveToLog(LOG_POS1, Write(write_Buffer,lba,num_of_sect,0,0);
	if((ec = ProjCmd.Write(lba,write_buffer,1,0,0) != EC_NOERROR)
	{
		SaveToLog(LOG_ERR1, "Write Wrapper failed. Unexpected ec: 0x%x", ec);
		return false;
	}

	SAVEToLog(LOG_STEP, "Verify if Write Command Successfully Completed");

	ProjCmd.Sensekey(EC_NOERROR, "Write Command did not return Good Status");
	SaveToLog(LOG_MSG1, "Write command erturned Good Status");


	SaveToLog(LOG_STEP2, "Issue Read Command by giving the input parameters");

	if((ec= ProjCmd.Read(lba,Read_buffer,num_of_sect,0,0) != EC_NOERROR)
	{
		SaveToLog(LOG_ERR, "Read Wrapper failed, Unexpected ec: 0x%x",ec);
		return false;
	}
	ProjCmd.parser.AssertSenseKey(EC_NOERROR, "Read Command did not return Good Status");
	SaveToLog(LOG_STEP,"Verify if Read returned  correct amount of data");
	
	ProjCmd.parser.GetReturnLength(dataTransLen);

	if(dataTransLen != 512)
	{

		SaveToLog(LOG_ERR, "Read Command did not transfer the correct amount of data");
        return false;
	}

	SaveToLog(LOG_MSG, "Read Buffer & Write Buffer is same");

	return true;

推荐答案

http://www .cplusplus.com/reference/clibrary/cstring/memcmp/ [ ^ ]

http://www.cplusplus.com/reference/clibrary/cstring/memcmp/[^]

<pre lang="c++">

if ( memcmp ( read_Buffer, write_Buffer, len ) != 0 )
   throw -1;  // Or whatever you want to throw...

</pre>


这篇关于如何在C ++中确保正确比较Write Buffer和Read Buffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆