I defined a struct in my header file:
#import <UIKit/UIKit.h>
typedef struct ORIGINAL_QUOTA_DATA_tag
{
byte exch; 开发者_运维技巧
byte complex_stat;
char contract[8];
byte status;
byte type;
}ORIGINAL_QUOTA_DATA;
@interface NetTestAppDelegate : NSObject <UIApplicationDelegate> {
CFSocketRef _socket;
CFDataRef address;
ORIGINAL_QUOTA_DATA oQuota;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
in my .m file:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(&oQuota, 0, sizeof(oQuota));
}
but it gets worning:
You are referencing oQuota
from C function (it's also static but that's not the problem). Your oQuota
variable is only "in scope" inside Objective-C methods implementation for your NetTestAppDelegate
:
void myCFunction()
{
// oQuota cannot be referenced here.
}
@implementation NetTestAppDelegate
- (void)myObjectiveCMethod
{
// oQuota is in scope, can reference it.
}
@end
But what you can do is pass the object to your callback:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(
&((NetTestAppDelegate *)info)->oQuota,
0,
sizeof(((NetTestAppDelegate *)info)->oQuota)
);
// Not sure whether the sizeof works, try it.
}
In your CFSocketContext
, you then need to set:
myCFSocketContext.info = self;
精彩评论